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