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