summaryrefslogtreecommitdiff
path: root/form.cgi
blob: 28baa3d90430ad1d4cab0c0234e86df71baf2876 (plain)
  1. #!/usr/bin/perl -w
  2. use CGI::FormBuilder;
  3. use utf8::all;
  4. my $build_path = '../build';
  5. # TODO: check if protocol-agnostic URL works
  6. my $webroot = 'http://byvandring.nu/feedback/';
  7. my $req_path = $build_path . '/html/feedback/index.html';
  8. my $ack_path = $build_path . '/html/feedback/tak/index.html';
  9. # Set this to 1 for a separate confirmation page
  10. my ($confirm) = 1;
  11. # Built-in email validation is too simplistic
  12. my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/';
  13. my $form = CGI::FormBuilder->new(
  14. lang => 'da',
  15. title => 'Feedback til Byvandring.nu',
  16. method => 'POST',
  17. fields => [qw/
  18. kommentar
  19. postnr
  20. email
  21. /],
  22. validate => {
  23. postnr => INT,
  24. email => $valid_email,
  25. _email => $valid_email, #fake check to silence warning of variable used only once
  26. },
  27. required => [qw/
  28. kommentar
  29. /],
  30. messages => ':da_DK',
  31. submit => ['Send oplysningerne'],
  32. action => $webroot, #avoids loosing submitted values when redirected from other site
  33. );
  34. $form->field(
  35. name => 'postnr',
  36. label => 'Postnummer',
  37. size => 5,
  38. comment => '(hvis du har lyst)'
  39. );
  40. $form->field(
  41. name => 'email',
  42. comment => '(hvis du vil kontaktes igen)'
  43. );
  44. $form->field(
  45. name => 'kommentar',
  46. type => 'textarea',
  47. rows => 3,
  48. );
  49. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  50. my ($mail_from) = $form->field('email') || undef;
  51. my ($mail_to, $mail_subject);
  52. if ($form->submitted) {
  53. $infostring = "Tak for din feedback!";
  54. if ($form->validate) {
  55. # $mail_to = 'info@byvandring.nu';
  56. $mail_to = 'siri@jones.dk';
  57. $mail_subject = 'Feedback til Byvandring.nu';
  58. } else {
  59. # $mail_to = 'siri@jones.dk, info@byvandring.nu';
  60. $mail_to = 'siri@jones.dk';
  61. $mail_subject = 'FEJL ved feedback til Byvandring.nu';
  62. $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.";
  63. $confirm = 0;
  64. };
  65. # if ($form->field('email')) {
  66. # $infostring .= "\n<P>Der er sendt en kopi af tilmeldingen til " . $form->field('email') . ".";
  67. # $mail_to .= ', ' . $form->field('email');
  68. # }
  69. # Abuse subject to add additional headers
  70. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  71. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  72. $form->mailresults(
  73. to => "$mail_to",
  74. from => $mail_from,
  75. # subject => "$mail_subject: " . $form->field('brugergruppe_navn'),
  76. subject => "$mail_subject",
  77. );
  78. if ($confirm) {
  79. $infostring .= "\n<P>Følgende informationer er blevet sendt:";
  80. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  81. print $form->confirm(
  82. header => 1,
  83. template => $ack_path
  84. );
  85. } else {
  86. print $form->render(
  87. header => 1,
  88. sticky => (! $form->validate),
  89. #FIXME text => $infostring,
  90. template => $req_path
  91. );
  92. }
  93. } else {
  94. print $form->render(
  95. header => 1,
  96. template => $req_path
  97. );
  98. }