summaryrefslogtreecommitdiff
path: root/contact.cgi
blob: 7256b5af2e0c1f88ff526432e065e5e4b8629dbe (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. name
  21. email
  22. human
  23. eyes
  24. comment
  25. /],
  26. validate => {
  27. email => $valid_email,
  28. _email => $valid_email, #fake check to silence warning of variable used only once
  29. },
  30. required => [qw/
  31. name
  32. email
  33. human
  34. /],
  35. messages => ':en_US',
  36. submit => ['Submit', 'Submit via secure connection'],
  37. action => $webroot, #avoids loosing submitted values when redirected from other site
  38. );
  39. $form->field(
  40. name => 'name',
  41. );
  42. $form->field(
  43. name => 'email',
  44. );
  45. $form->field(
  46. name => 'human',
  47. label => '',
  48. options => ["I'm not a robot!"],
  49. multiple => 0,
  50. jsmessage => '- Sorry, no robots allowed!',
  51. );
  52. $form->field(
  53. name => 'eyes',
  54. label => 'eye color',
  55. options => [qw(blue green other)],
  56. type => 'select',
  57. );
  58. $form->field(
  59. name => 'comment',
  60. type => 'textarea',
  61. rows => 5,
  62. );
  63. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  64. my ($mail_from) = $webmaster;
  65. my ($mail_to, $mail_subject);
  66. if ($form->submitted) {
  67. $infostring = "Thanks for your interest in omni-presence!";
  68. if ($form->validate) {
  69. $mail_to = $frontdesk;
  70. $mail_subject = 'Omni-presence contact form';
  71. } else {
  72. $mail_to = "$frontdesk, $helpdesk";
  73. $mail_subject = 'ERROR in omni-presence contact form';
  74. $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.";
  75. $confirm = 0;
  76. };
  77. # Abuse subject to add additional headers
  78. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  79. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  80. $form->mailresults(
  81. to => $mail_to,
  82. from => $mail_from,
  83. subject => "$mail_subject",
  84. );
  85. if ($confirm) {
  86. $infostring .= "\n<P>The following info has been submitted:";
  87. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  88. print $form->confirm(
  89. header => 1,
  90. template => $ack_path
  91. );
  92. } else {
  93. print $form->render(
  94. header => 1,
  95. sticky => (! $form->validate),
  96. #FIXME text => $infostring,
  97. template => $req_path
  98. );
  99. }
  100. } else {
  101. print $form->render(
  102. header => 1,
  103. template => $req_path
  104. );
  105. }