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