summaryrefslogtreecommitdiff
path: root/contact.cgi
blob: 036782c45ad9a4b9d0066ea6a4e9b69968e8d6ee (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://form.omni-presence.dk/contact/';
  6. my $req_path = $build_path . '/html/contact/index.html';
  7. my $ack_path = $build_path . '/html/contact/thanks/index.html';
  8. my $webmaster = 'webmaster@omni-presence.dk';
  9. my $frontdesk = 'info@omni-presence.dk';
  10. my $helpdesk = 'dr@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 => 'en',
  17. title => 'Omni-presence contact form',
  18. method => 'POST',
  19. fields => [qw/
  20. comment
  21. zip
  22. email
  23. /],
  24. validate => {
  25. zip => INT,
  26. email => $valid_email,
  27. _email => $valid_email, #fake check to silence warning of variable used only once
  28. },
  29. required => [qw/
  30. comment
  31. /],
  32. messages => ':en_US',
  33. submit => ['Send the info'],
  34. action => $webroot, #avoids loosing submitted values when redirected from other site
  35. );
  36. $form->field(
  37. name => 'zip',
  38. label => 'Postal nummer',
  39. size => 5,
  40. );
  41. $form->field(
  42. name => 'email',
  43. );
  44. $form->field(
  45. name => 'comment',
  46. type => 'textarea',
  47. rows => 3,
  48. );
  49. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  50. my ($mail_from) = $webmaster;
  51. my ($mail_to, $mail_subject);
  52. if ($form->submitted) {
  53. $infostring = "Thanks for your interest in omni-presence!";
  54. if ($form->validate) {
  55. $mail_to = $frontdesk;
  56. $mail_subject = 'Omni-presence contact form';
  57. } else {
  58. $mail_to = "$frontdesk, $helpdesk";
  59. $mail_subject = 'ERROR in omni-presence contact form';
  60. $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.";
  61. $confirm = 0;
  62. };
  63. # Abuse subject to add additional headers
  64. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  65. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  66. $form->mailresults(
  67. to => $mail_to,
  68. from => $mail_from,
  69. subject => "$mail_subject",
  70. );
  71. if ($confirm) {
  72. $infostring .= "\n<P>The following info has been submitted:";
  73. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  74. print $form->confirm(
  75. header => 1,
  76. template => $ack_path
  77. );
  78. } else {
  79. print $form->render(
  80. header => 1,
  81. sticky => (! $form->validate),
  82. #FIXME text => $infostring,
  83. template => $req_path
  84. );
  85. }
  86. } else {
  87. print $form->render(
  88. header => 1,
  89. template => $req_path
  90. );
  91. }