summaryrefslogtreecommitdiff
path: root/feedback.cgi
blob: 23c3023b070335e014a9ad3a5e05c41d714f46c9 (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/feedback/';
  8. my $req_path = $build_path . '/html/feedback/index.html';
  9. my $ack_path = $build_path . '/html/feedback/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 => 'Feedback til Byvandring.nu',
  20. method => 'POST',
  21. fields => [qw/
  22. kommentar
  23. postnr
  24. email
  25. /],
  26. validate => {
  27. postnr => INT,
  28. email => $valid_email,
  29. _email => $valid_email, #fake check to silence warning of variable used only once
  30. },
  31. required => [qw/
  32. kommentar
  33. /],
  34. messages => ':da_DK',
  35. submit => ['Send oplysningerne'],
  36. action => $webroot, #avoids loosing submitted values when redirected from other site
  37. );
  38. $form->field(
  39. name => 'postnr',
  40. label => 'Postnummer',
  41. size => 5,
  42. comment => '(hvis du har lyst)'
  43. );
  44. $form->field(
  45. name => 'email',
  46. comment => '(hvis du vil kontaktes igen)'
  47. );
  48. $form->field(
  49. name => 'kommentar',
  50. type => 'textarea',
  51. rows => 3,
  52. );
  53. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  54. my ($mail_from) = $webmaster;
  55. my ($mail_to, $mail_subject);
  56. if ($form->submitted) {
  57. $infostring = "Tak for din feedback!";
  58. if ($form->validate) {
  59. $mail_to = $frontdesk;
  60. $mail_subject = 'Feedback til Byvandring.nu';
  61. } else {
  62. $mail_to = "$frontdesk, $helpdesk";
  63. $mail_subject = 'FEJL ved feedback til Byvandring.nu';
  64. $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.";
  65. $confirm = 0;
  66. };
  67. # Abuse subject to add additional headers
  68. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  69. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  70. $form->mailresults(
  71. to => $mail_to,
  72. from => $mail_from,
  73. subject => "$mail_subject",
  74. );
  75. if ($confirm) {
  76. $infostring .= "\n<P>Følgende informationer er blevet sendt:";
  77. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  78. print $form->confirm(
  79. header => 1,
  80. template => $ack_path
  81. );
  82. } else {
  83. print $form->render(
  84. header => 1,
  85. sticky => (! $form->validate),
  86. #FIXME text => $infostring,
  87. template => $req_path
  88. );
  89. }
  90. } else {
  91. print $form->render(
  92. header => 1,
  93. template => $req_path
  94. );
  95. }
  96. 1;