summaryrefslogtreecommitdiff
path: root/fribillet.cgi
blob: bdf486bf2aee131cf941574a4e5f566d61e75b47 (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/fribillet/';
  8. my $req_path = $build_path . '/html/fribillet/index.html';
  9. my $ack_path = $build_path . '/html/fribillet/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 $form = CGI::FormBuilder->new(
  18. lang => 'da',
  19. title => 'Fribillet til byvandring',
  20. method => 'POST',
  21. fields => [qw/
  22. navn
  23. modtager
  24. postnr
  25. email
  26. tur
  27. antal
  28. tid
  29. kommentar
  30. /],
  31. validate => {
  32. email => $valid_email,
  33. _email => $valid_email, #fake check to silence warning of variable used only once
  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 => 'modtager',
  49. label => 'Modtager',
  50. comment => '(hvem du vil invitere)'
  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 = 'Fribillet til byvandring';
  89. } else {
  90. $mail_to = "$frontdesk, $helpdesk";
  91. $mail_subject = 'FEJL vedr. fribillet til byvandring';
  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. $form->mailresults(
  99. to => $mail_to,
  100. from => $mail_from,
  101. subject => "$mail_subject",
  102. );
  103. if ($confirm) {
  104. $infostring .= "\n<P>Følgende informationer er blevet sendt:";
  105. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  106. print $form->confirm(
  107. header => 1,
  108. template => $ack_path
  109. );
  110. } else {
  111. print $form->render(
  112. header => 1,
  113. sticky => (! $form->validate),
  114. #FIXME text => $infostring,
  115. template => $req_path
  116. );
  117. }
  118. } else {
  119. print $form->render(
  120. header => 1,
  121. template => $req_path
  122. );
  123. }
  124. 1;