summaryrefslogtreecommitdiff
path: root/vejviseren/familieture.cgi
blob: 1d7dd978aebfabfcf5a581d3a209feb66743fb0a (plain)
  1. #!/usr/bin/perl -w
  2. use CGI::FormBuilder;
  3. my $build_path = '../build';
  4. # TODO: check if protocol-agnostic URL works
  5. my $webroot = 'https://byvandring.nu/vejviseren/familieture/';
  6. my $req_path = $build_path . '/html/vejviseren/familieture/index.html';
  7. my $ack_path = $build_path . '/html/vejviseren/familieture/tak/index.html';
  8. my $webmaster = 'info@byvandring.nu';
  9. my $frontdesk = 'info@byvandring.nu';
  10. my $helpdesk = 'siri@jones.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 => 'da',
  17. title => 'Henvendelse til Byvandring.nu',
  18. method => 'POST',
  19. fields => [qw/
  20. navn
  21. org
  22. postnr
  23. email
  24. tur
  25. antal
  26. tid
  27. kommentar
  28. /],
  29. validate => {
  30. email => $valid_email,
  31. _email => $valid_email, #fake check to silence warning of variable used only once
  32. },
  33. required => [qw/
  34. email
  35. /],
  36. messages => ':da_DK',
  37. submit => ['Send oplysningerne'],
  38. action => $webroot, #avoids loosing submitted values when redirected from other site
  39. );
  40. $form->field(
  41. name => 'navn',
  42. label => 'Navn',
  43. comment => '(dit eget navn)'
  44. );
  45. $form->field(
  46. name => 'org',
  47. label => 'Firma/ skole',
  48. comment => '(hvem du repræsenterer)'
  49. );
  50. $form->field(
  51. name => 'postnr',
  52. label => 'Postnummer',
  53. size => 5,
  54. comment => '(hvis du har lyst)'
  55. );
  56. $form->field(
  57. name => 'tur',
  58. label => 'Tur',
  59. size => 5,
  60. comment => '(turnavn, bydel eller tema)'
  61. );
  62. $form->field(
  63. name => 'antal',
  64. label => 'Antal',
  65. size => 5,
  66. comment => '(antal deltagere)'
  67. );
  68. $form->field(
  69. name => 'tid',
  70. label => 'Tidspunkt',
  71. size => 5,
  72. comment => '(dato og tidspunkt)'
  73. );
  74. $form->field(
  75. name => 'kommentar',
  76. type => 'textarea',
  77. rows => 3,
  78. );
  79. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  80. my ($mail_from) = $webmaster;
  81. my ($mail_to, $mail_subject);
  82. if ($form->submitted) {
  83. $infostring = "Tak for din henvendelse!";
  84. if ($form->validate) {
  85. $mail_to = $frontdesk;
  86. $mail_subject = 'Henvendelse til Byvandring.nu';
  87. } else {
  88. $mail_to = "$frontdesk, $helpdesk";
  89. $mail_subject = 'FEJL ved henvendelse til Byvandring.nu';
  90. $infostring .= "\n<P>OBS! Der var fejl i et eller flere af felterne. Informationerne er sendt uanset, men det anbefales at gå tilbage, checke at alle felter er udfyldt korrekt, og derefter sende igen.";
  91. $confirm = 0;
  92. };
  93. # Abuse subject to add additional headers
  94. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  95. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  96. $form->mailresults(
  97. to => $mail_to,
  98. from => $mail_from,
  99. subject => "$mail_subject",
  100. );
  101. if ($confirm) {
  102. $infostring .= "\n<P>Følgende informationer er blevet sendt:";
  103. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  104. print $form->confirm(
  105. header => 1,
  106. template => $ack_path
  107. );
  108. } else {
  109. print $form->render(
  110. header => 1,
  111. sticky => (! $form->validate),
  112. #FIXME text => $infostring,
  113. template => $req_path
  114. );
  115. }
  116. } else {
  117. print $form->render(
  118. header => 1,
  119. template => $req_path
  120. );
  121. }