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