summaryrefslogtreecommitdiff
path: root/kontakt.cgi
blob: 3bc86565f14d3a69368015f09c6b3b55a850a4ee (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/kontakt/';
  6. my $req_path = $build_path . '/html/kontakt/index.html';
  7. my $ack_path = $build_path . '/html/kontakt/tak/index.html';
  8. my $webmaster = 'info@byvandring.nu';
  9. #my $frontdesk = 'info@byvandring.nu';
  10. my $frontdesk = 'siri@jones.dk';
  11. my $helpdesk = 'siri@jones.dk';
  12. # Set this to 1 for a separate confirmation page
  13. my ($confirm) = 1;
  14. # Built-in email validation is too simplistic
  15. my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/';
  16. my $form = CGI::FormBuilder->new(
  17. lang => 'da',
  18. title => 'Henvendelse til Byvandring.nu',
  19. method => 'POST',
  20. fields => [qw/
  21. navn
  22. org
  23. postnr
  24. email
  25. tur
  26. antal
  27. tid
  28. kommentar
  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. email
  36. /],
  37. messages => ':da_DK',
  38. submit => ['Send oplysningerne'],
  39. action => $webroot, #avoids loosing submitted values when redirected from other site
  40. );
  41. $form->field(
  42. name => 'navn',
  43. label => 'Navn',
  44. comment => '(dit eget navn)'
  45. );
  46. $form->field(
  47. name => 'org',
  48. label => 'Firma/ skole',
  49. comment => '(hvem du repræsenterer)'
  50. );
  51. $form->field(
  52. name => 'postnr',
  53. label => 'Postnummer',
  54. size => 5,
  55. comment => '(hvis du har lyst)'
  56. );
  57. $form->field(
  58. name => 'tur',
  59. label => 'Tur',
  60. size => 5,
  61. comment => '(Tur, bydel eller tema)'
  62. );
  63. $form->field(
  64. name => 'antal',
  65. label => 'Antal',
  66. size => 5,
  67. comment => '(Antal deltagere)'
  68. );
  69. $form->field(
  70. name => 'tid',
  71. label => 'Tidspunkt',
  72. size => 5,
  73. comment => '(Dato og tidspunkt)'
  74. );
  75. $form->field(
  76. name => 'kommentar',
  77. type => 'textarea',
  78. rows => 3,
  79. );
  80. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  81. my ($mail_from) = $webmaster;
  82. my ($mail_to, $mail_subject);
  83. if ($form->submitted) {
  84. $infostring = "Tak for din henvendelse!";
  85. if ($form->validate) {
  86. $mail_to = $frontdesk;
  87. $mail_subject = 'Henvendelse til Byvandring.nu';
  88. } else {
  89. $mail_to = "$frontdesk, $helpdesk";
  90. $mail_subject = 'FEJL ved henvendelse til Byvandring.nu';
  91. $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.";
  92. $confirm = 0;
  93. };
  94. # Abuse subject to add additional headers
  95. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  96. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  97. $form->mailresults(
  98. to => $mail_to,
  99. from => $mail_from,
  100. subject => "$mail_subject",
  101. );
  102. if ($confirm) {
  103. $infostring .= "\n<P>Følgende informationer er blevet sendt:";
  104. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  105. print $form->confirm(
  106. header => 1,
  107. template => $ack_path
  108. );
  109. } else {
  110. print $form->render(
  111. header => 1,
  112. sticky => (! $form->validate),
  113. #FIXME text => $infostring,
  114. template => $req_path
  115. );
  116. }
  117. } else {
  118. print $form->render(
  119. header => 1,
  120. template => $req_path
  121. );
  122. }