From 914047920521883cf78aa52d0b69164fe9344842 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 3 Apr 2017 10:44:37 +0200 Subject: Reanem form → contact. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contact.cgi | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ form.cgi | 102 ------------------------------------------------------------ 2 files changed, 102 insertions(+), 102 deletions(-) create mode 100755 contact.cgi delete mode 100755 form.cgi diff --git a/contact.cgi b/contact.cgi new file mode 100755 index 0000000..16242c3 --- /dev/null +++ b/contact.cgi @@ -0,0 +1,102 @@ +#!/usr/bin/perl -w + +use CGI::FormBuilder; + +my $build_path = '../build'; + +# TODO: check if protocol-agnostic URL works +my $webroot = 'https://omni-presence.dk/contact/'; +my $req_path = $build_path . '/html/contact/index.html'; +my $ack_path = $build_path . '/html/contact/thanks/index.html'; + +my $webmaster = 'webmaster@couchdesign.dk'; +#my $frontdesk = 'info@omni-presence.dk'; +my $frontdesk = 'anniqalewis@gmail.com'; +my $helpdesk = 'dr@jones.dk'; + +# Set this to 1 for a separate confirmation page +my ($confirm) = 1; + +# Built-in email validation is too simplistic +my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/'; + +my $form = CGI::FormBuilder->new( + lang => 'en', + title => 'Omni-presence contact form', + method => 'POST', + fields => [qw/ + comment + zip + email + /], + validate => { + zip => INT, + email => $valid_email, + _email => $valid_email, #fake check to silence warning of variable used only once + }, + required => [qw/ + comment + /], + messages => ':en_US', + submit => ['Send the info'], + action => $webroot, #avoids loosing submitted values when redirected from other site +); + +$form->field( + name => 'zip', + label => 'Postal nummer', + size => 5, +); +$form->field( + name => 'email', +); +$form->field( + name => 'comment', + type => 'textarea', + rows => 3, +); + +my ($form_required_text) = $form->{opt}{messages}{form_required_text}; +my ($mail_from) = $webmaster; +my ($mail_to, $mail_subject); + +if ($form->submitted) { + $infostring = "Thanks for your interest in omni-presence!"; + if ($form->validate) { + $mail_to = $frontdesk; + $mail_subject = 'Omni-presence contact form'; + } else { + $mail_to = "$frontdesk, $helpdesk"; + $mail_subject = 'ERROR in omni-presence contact form'; + $infostring .= "\n

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."; + $confirm = 0; + }; + # Abuse subject to add additional headers +# $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";'; +# $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit'; + $form->mailresults( + to => $mail_to, + from => $mail_from, + subject => "$mail_subject", + ); + if ($confirm) { + $infostring .= "\n

The following info has been submitted:"; + $form->{opt}{messages}{form_confirm_text} = "$infostring"; + print $form->confirm( + header => 1, + template => $ack_path + ); + } else { + print $form->render( + header => 1, + sticky => (! $form->validate), +#FIXME text => $infostring, + template => $req_path + ); + } +} else { + print $form->render( + header => 1, + template => $req_path + ); +} diff --git a/form.cgi b/form.cgi deleted file mode 100755 index 16242c3..0000000 --- a/form.cgi +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/perl -w - -use CGI::FormBuilder; - -my $build_path = '../build'; - -# TODO: check if protocol-agnostic URL works -my $webroot = 'https://omni-presence.dk/contact/'; -my $req_path = $build_path . '/html/contact/index.html'; -my $ack_path = $build_path . '/html/contact/thanks/index.html'; - -my $webmaster = 'webmaster@couchdesign.dk'; -#my $frontdesk = 'info@omni-presence.dk'; -my $frontdesk = 'anniqalewis@gmail.com'; -my $helpdesk = 'dr@jones.dk'; - -# Set this to 1 for a separate confirmation page -my ($confirm) = 1; - -# Built-in email validation is too simplistic -my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/'; - -my $form = CGI::FormBuilder->new( - lang => 'en', - title => 'Omni-presence contact form', - method => 'POST', - fields => [qw/ - comment - zip - email - /], - validate => { - zip => INT, - email => $valid_email, - _email => $valid_email, #fake check to silence warning of variable used only once - }, - required => [qw/ - comment - /], - messages => ':en_US', - submit => ['Send the info'], - action => $webroot, #avoids loosing submitted values when redirected from other site -); - -$form->field( - name => 'zip', - label => 'Postal nummer', - size => 5, -); -$form->field( - name => 'email', -); -$form->field( - name => 'comment', - type => 'textarea', - rows => 3, -); - -my ($form_required_text) = $form->{opt}{messages}{form_required_text}; -my ($mail_from) = $webmaster; -my ($mail_to, $mail_subject); - -if ($form->submitted) { - $infostring = "Thanks for your interest in omni-presence!"; - if ($form->validate) { - $mail_to = $frontdesk; - $mail_subject = 'Omni-presence contact form'; - } else { - $mail_to = "$frontdesk, $helpdesk"; - $mail_subject = 'ERROR in omni-presence contact form'; - $infostring .= "\n

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."; - $confirm = 0; - }; - # Abuse subject to add additional headers -# $mail_subject .= "\n" . 'Content-Type: text/plain; charset="ISO-8859-1";'; -# $mail_subject .= "\n" . 'Content-Transfer-Encoding: 8bit'; - $form->mailresults( - to => $mail_to, - from => $mail_from, - subject => "$mail_subject", - ); - if ($confirm) { - $infostring .= "\n

The following info has been submitted:"; - $form->{opt}{messages}{form_confirm_text} = "$infostring"; - print $form->confirm( - header => 1, - template => $ack_path - ); - } else { - print $form->render( - header => 1, - sticky => (! $form->validate), -#FIXME text => $infostring, - template => $req_path - ); - } -} else { - print $form->render( - header => 1, - template => $req_path - ); -} -- cgit v1.2.3