summaryrefslogtreecommitdiff
path: root/book/index.cgi
blob: 7b8339cf8db0a866ef236ea6fd101338bc2f2064 (plain)
  1. #!/usr/bin/perl -w
  2. use CGI::FormBuilder;
  3. my $docroot = '../build/html';
  4. # TODO: check if protocol-agnostic URL works
  5. my $webroot = 'https://stadsvandring.dk/book-form';
  6. my $req_path = $docroot . '/book/index.tmpl';
  7. my $ack_path = $docroot . '/book/thanks/index.html';
  8. my $webmaster = 'webmaster@stadsvandring.dk';
  9. my $frontdesk = 'stadsvandring@stadsvandring.dk';
  10. my $helpdesk = 'webmaster@stadsvandring.dk';
  11. # Set this to 1 for a separate confirmation page
  12. my ($confirm) = 1;
  13. # Built-in email validation is too simplistic
  14. my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/';
  15. my $form = CGI::FormBuilder->new(
  16. lang => 'sv',
  17. title => 'Din næste stadsvandring',
  18. method => 'POST',
  19. fields => [qw/
  20. requests
  21. places
  22. time
  23. size
  24. name
  25. org
  26. email
  27. addr
  28. misc
  29. /],
  30. validate => {
  31. email => $valid_email,
  32. _email => $valid_email, #fake check to silence warning of variable used only once
  33. },
  34. required => [qw/
  35. name
  36. email
  37. requests
  38. /],
  39. messages => ':sv_SE',
  40. # submit => ['Submit'],
  41. action => $webroot, #avoids loosing submitted values when redirected from other site
  42. );
  43. $form->field(
  44. name => 'requests',
  45. label => 'Önskemål om tur',
  46. type => 'textarea',
  47. rows => 3,
  48. );
  49. $form->field(
  50. name => 'places',
  51. label => 'Önskemål om start och– slut på turenlokalitet',
  52. type => 'textarea',
  53. rows => 3,
  54. );
  55. $form->field(
  56. name => 'time',
  57. label => 'Datum och tid',
  58. );
  59. $form->field(
  60. name => 'size',
  61. label => 'Gruppstorlek',
  62. );
  63. $form->field(
  64. name => 'name',
  65. label => 'Namn',
  66. );
  67. $form->field(
  68. name => 'org',
  69. label => 'Företag eller institution',
  70. );
  71. $form->field(
  72. name => 'email',
  73. label => 'Mailadress',
  74. );
  75. $form->field(
  76. name => 'addr',
  77. label => 'Adress och telefonnummer',
  78. type => 'textarea',
  79. rows => 3,
  80. );
  81. $form->field(
  82. name => 'misc',
  83. label => 'Andra upplysningar om gruppen och andra önskemål om turen',
  84. type => 'textarea',
  85. rows => 6,
  86. );
  87. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  88. my ($mail_from) = $webmaster;
  89. my ($mail_to, $mail_subject);
  90. if ($form->submitted) {
  91. $infostring = "Tak for din booking-ansøgning ved stadsvandring.dk - du vil snarest blive kontaktet!";
  92. if ($form->validate) {
  93. $mail_to = $frontdesk;
  94. $mail_subject = 'stadsvandring.dk booking-ansøgning';
  95. } else {
  96. $mail_to = "$frontdesk, $helpdesk";
  97. $mail_subject = 'FEL i stadsvandring.dk booking-ansökan';
  98. $infostring .= "\n<P>NB! Det var en FEL i en eller flere af telterne. Din ansökan blev sendt alligevel, men vi anbefaler at du checker igen at blanketten er korrekt udfyldt og sender den igen.";
  99. $confirm = 0;
  100. };
  101. # Abuse subject to add additional headers
  102. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  103. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  104. $form->mailresults(
  105. to => $mail_to,
  106. from => $mail_from,
  107. subject => "$mail_subject",
  108. );
  109. if ($confirm) {
  110. $infostring .= "\n<P>Følgende informationer blev sendt:";
  111. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  112. print $form->confirm(
  113. header => 1,
  114. template => $ack_path
  115. );
  116. } else {
  117. printhack( $form->render(
  118. header => 1,
  119. sticky => (! $form->validate),
  120. #FIXME text => $infostring,
  121. template => $req_path
  122. ));
  123. }
  124. } elsif ($ENV{'FORMBUILDER_NOHEADER'}) {
  125. printhack( $form->render(
  126. header => 0,
  127. template => $req_path
  128. ));
  129. } else {
  130. printhack( $form->render(
  131. header => 1,
  132. template => $req_path
  133. ));
  134. }
  135. # fix charset in header
  136. sub printhack {
  137. $_ = shift;
  138. s,charset=\Kiso\-8859\-1,utf-8,;
  139. print $_;
  140. }