summaryrefslogtreecommitdiff
path: root/contact.cgi
blob: bd79eefd9ce4a44d2706463f51fd6a6996a5551e (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. class => 'form-control',
  42. );
  43. $form->field(
  44. name => 'email',
  45. id => 'inputEmail',
  46. class => 'form-control',
  47. placeholder => 'Email',
  48. );
  49. $form->field(
  50. name => 'human',
  51. label => '',
  52. class => 'checkbox',
  53. options => ["I'm not a robot!"],
  54. multiple => 0,
  55. message => '- Sorry, no robots allowed!',
  56. );
  57. $form->field(
  58. name => 'eyes',
  59. label => 'eye color',
  60. class => 'form-control',
  61. type => 'select',
  62. options => [qw(blue green other)],
  63. );
  64. $form->field(
  65. name => 'comment',
  66. class => 'form-control',
  67. type => 'textarea',
  68. rows => 5,
  69. );
  70. my ($form_required_text) = $form->{opt}{messages}{form_required_text};
  71. my ($mail_from) = $webmaster;
  72. my ($mail_to, $mail_subject);
  73. if ($form->submitted) {
  74. $infostring = "Thanks for your interest in omni-presence!";
  75. if ($form->validate) {
  76. $mail_to = $frontdesk;
  77. $mail_subject = 'Omni-presence contact form';
  78. } else {
  79. $mail_to = "$frontdesk, $helpdesk";
  80. $mail_subject = 'ERROR in omni-presence contact form';
  81. $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.";
  82. $confirm = 0;
  83. };
  84. # Abuse subject to add additional headers
  85. # $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";';
  86. # $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit';
  87. $form->mailresults(
  88. to => $mail_to,
  89. from => $mail_from,
  90. subject => "$mail_subject",
  91. );
  92. if ($confirm) {
  93. $infostring .= "\n<P>The following info has been submitted:";
  94. $form->{opt}{messages}{form_confirm_text} = "$infostring";
  95. print $form->confirm(
  96. # header => 1,
  97. template => $ack_path
  98. );
  99. } else {
  100. print $form->render(
  101. # header => 1,
  102. sticky => (! $form->validate),
  103. #FIXME text => $infostring,
  104. template => $req_path
  105. );
  106. }
  107. } else {
  108. print $form->render(
  109. # header => 1,
  110. template => $req_path
  111. );
  112. }