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