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