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