From 4bdc3db9c4e7f720d3ed1a6d214f2cac9448fe57 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 19 Apr 2017 14:04:17 +0200 Subject: Change into booking request form. --- book/index.cgi | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ footer.cgi | 107 ---------------------------------------- 2 files changed, 151 insertions(+), 107 deletions(-) create mode 100755 book/index.cgi delete mode 100755 footer.cgi diff --git a/book/index.cgi b/book/index.cgi new file mode 100755 index 0000000..7b8339c --- /dev/null +++ b/book/index.cgi @@ -0,0 +1,151 @@ +#!/usr/bin/perl -w + +use CGI::FormBuilder; + +my $docroot = '../build/html'; + +# TODO: check if protocol-agnostic URL works +my $webroot = 'https://stadsvandring.dk/book-form'; +my $req_path = $docroot . '/book/index.tmpl'; +my $ack_path = $docroot . '/book/thanks/index.html'; + +my $webmaster = 'webmaster@stadsvandring.dk'; +my $frontdesk = 'stadsvandring@stadsvandring.dk'; +my $helpdesk = 'webmaster@stadsvandring.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 => 'sv', + title => 'Din næste stadsvandring', + method => 'POST', + fields => [qw/ + requests + places + time + size + name + org + email + addr + misc + /], + validate => { + email => $valid_email, + _email => $valid_email, #fake check to silence warning of variable used only once + }, + required => [qw/ + name + email + requests + /], + messages => ':sv_SE', +# submit => ['Submit'], + action => $webroot, #avoids loosing submitted values when redirected from other site +); + +$form->field( + name => 'requests', + label => 'Önskemål om tur', + type => 'textarea', + rows => 3, +); +$form->field( + name => 'places', + label => 'Önskemål om start och– slut på turenlokalitet', + type => 'textarea', + rows => 3, +); +$form->field( + name => 'time', + label => 'Datum och tid', +); +$form->field( + name => 'size', + label => 'Gruppstorlek', +); +$form->field( + name => 'name', + label => 'Namn', +); +$form->field( + name => 'org', + label => 'Företag eller institution', +); +$form->field( + name => 'email', + label => 'Mailadress', +); +$form->field( + name => 'addr', + label => 'Adress och telefonnummer', + type => 'textarea', + rows => 3, +); +$form->field( + name => 'misc', + label => 'Andra upplysningar om gruppen och andra önskemål om turen', + type => 'textarea', + rows => 6, +); + +my ($form_required_text) = $form->{opt}{messages}{form_required_text}; +my ($mail_from) = $webmaster; +my ($mail_to, $mail_subject); + +if ($form->submitted) { + $infostring = "Tak for din booking-ansøgning ved stadsvandring.dk - du vil snarest blive kontaktet!"; + if ($form->validate) { + $mail_to = $frontdesk; + $mail_subject = 'stadsvandring.dk booking-ansøgning'; + } else { + $mail_to = "$frontdesk, $helpdesk"; + $mail_subject = 'FEL i stadsvandring.dk booking-ansökan'; + $infostring .= "\n

NB! Det var en FEL i en eller flere af telterne. Din ansökan blev sendt alligevel, men vi anbefaler at du checker igen at blanketten er korrekt udfyldt og sender den igen."; + $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

Følgende informationer blev sendt:"; + $form->{opt}{messages}{form_confirm_text} = "$infostring"; + print $form->confirm( + header => 1, + template => $ack_path + ); + } else { + printhack( $form->render( + header => 1, + sticky => (! $form->validate), +#FIXME text => $infostring, + template => $req_path + )); + } +} elsif ($ENV{'FORMBUILDER_NOHEADER'}) { + printhack( $form->render( + header => 0, + template => $req_path + )); +} else { + printhack( $form->render( + header => 1, + template => $req_path + )); +} + +# fix charset in header +sub printhack { + $_ = shift; + s,charset=\Kiso\-8859\-1,utf-8,; + print $_; +} diff --git a/footer.cgi b/footer.cgi deleted file mode 100755 index d308e86..0000000 --- a/footer.cgi +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/perl -w - -use CGI::FormBuilder; - -my $docroot = '../build/html'; - -# TODO: check if protocol-agnostic URL works -my $webroot = 'https://stadsvandring.dk/form'; -my $req_path = $docroot . '/index.tmpl'; -my $ack_path = $docroot . '/thanks/index.html'; - -my $webmaster = 'webmaster@stadsvandring.dk'; -my $frontdesk = 'info@stadsvandring.dk'; -my $helpdesk = 'hostmaster@stadsvandring.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 => 'stadsvandring contact form', - method => 'POST', - fields => [qw/ - name - email - /], - validate => { - email => $valid_email, - _email => $valid_email, #fake check to silence warning of variable used only once - }, - required => [qw/ - name - email - /], - messages => ':en_US', - submit => ['Submit'], - action => $webroot, #avoids loosing submitted values when redirected from other site -); - -$form->field( - name => 'name', - placeholder => 'Name', -); -$form->field( - name => 'email', - placeholder => 'Email', -); - -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 stadsvandring.dk!"; - if ($form->validate) { - $mail_to = $frontdesk; - $mail_subject = 'stadsvandring.dk contact form'; - } else { - $mail_to = "$frontdesk, $helpdesk"; - $mail_subject = 'ERROR in stadsvandring.dk contact form'; - $infostring .= "\n

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."; - $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 { - printhack( $form->render( - header => 1, - sticky => (! $form->validate), -#FIXME text => $infostring, - template => $req_path - )); - } -} elsif ($ENV{'FORMBUILDER_NOHEADER'}) { - printhack( $form->render( - header => 0, - template => $req_path - )); -} else { - printhack( $form->render( - header => 1, - template => $req_path - )); -} - -# fix charset in header -sub printhack { - $_ = shift; - s,charset=\Kiso\-8859\-1,utf-8,; - print $_; -} -- cgit v1.2.3