summaryrefslogtreecommitdiff
path: root/footer.cgi
blob: 7081c98c5e654cb1dce16e10507c10260cf1844c (plain)
  1. #!/usr/bin/perl -w
  2. use CGI::FormBuilder;
  3. my $docroot = '../build/html';
  4. # TODO: check if protocol-agnostic URL works
  5. my $webroot = 'https://form.stadsvandring.dk/form';
  6. my $req_path = $docroot . '/index.tmpl';
  7. my $ack_path = $docroot . '/thanks/index.html';
  8. my $webmaster = 'webmaster@stadsvandring.dk';
  9. my $frontdesk = 'info@stadsvandring.dk';
  10. my $helpdesk = 'hostmaster@stadsvandring.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 => 'en',
  17. title => 'stadsvandring contact form',
  18. method => 'POST',
  19. fields => [qw/
  20. name
  21. email
  22. /],
  23. validate => {
  24. email => $valid_email,
  25. _email => $valid_email, #fake check to silence warning of variable used only once
  26. },
  27. required => [qw/
  28. name
  29. email
  30. /],
  31. messages => ':en_US',
  32. submit => ['Submit'],
  33. action => $webroot, #avoids loosing submitted values when redirected from other site
  34. );
  35. $form->field(
  36. name => 'name',
  37. placeholder => 'Name',
  38. );
  39. $form->field(
  40. name => 'email',
  41. placeholder => 'Email',
  42. );
  43. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  44. my ($mail_from) = $webmaster;
  45. my ($mail_to, $mail_subject);
  46. if ($form->submitted) {
  47. $infostring = "Thanks for your interest in stadsvandring.dk!";
  48. if ($form->validate) {
  49. $mail_to = $frontdesk;
  50. $mail_subject = 'stadsvandring.dk contact form';
  51. } else {
  52. $mail_to = "$frontdesk, $helpdesk";
  53. $mail_subject = 'ERROR in stadsvandring.dk contact form';
  54. $infostring .= "\n<P>NB! There was an error in one or more of the fields. The info was sent anyway, but you are adviced to go back, check that all fields are properly filed out, and then send again.";
  55. $confirm = 0;
  56. };
  57. # Abuse subject to add additional headers
  58. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  59. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  60. $form->mailresults(
  61. to => $mail_to,
  62. from => $mail_from,
  63. subject => "$mail_subject",
  64. );
  65. if ($confirm) {
  66. $infostring .= "\n<P>The following info has been submitted:";
  67. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  68. print $form->confirm(
  69. header => 1,
  70. template => $ack_path
  71. );
  72. } else {
  73. printhack( $form->render(
  74. header => 1,
  75. sticky => (! $form->validate),
  76. #FIXME text => $infostring,
  77. template => $req_path
  78. ));
  79. }
  80. } elsif ($ENV{'FORMBUILDER_NOHEADER'}) {
  81. printhack( $form->render(
  82. header => 0,
  83. template => $req_path
  84. ));
  85. } else {
  86. printhack( $form->render(
  87. header => 1,
  88. template => $req_path
  89. ));
  90. }
  91. # fix charset in header
  92. sub printhack {
  93. $_ = shift;
  94. s,charset=\Kiso\-8859\-1,utf-8,;
  95. print $_;
  96. }