diff options
author | Jonas Smedegaard <dr@jones.dk> | 2015-02-26 14:58:16 +0100 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2015-02-26 14:58:16 +0100 |
commit | 97b06666b03a090904a9d7e74536cc466ecf43f7 (patch) | |
tree | 7663647ed23e6a5b6661458ed81f7e6f4d79d2f6 /form.cgi |
Initial draft.
Diffstat (limited to 'form.cgi')
-rwxr-xr-x | form.cgi | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/form.cgi b/form.cgi new file mode 100755 index 0000000..d4d7c4e --- /dev/null +++ b/form.cgi @@ -0,0 +1,102 @@ +#!/usr/bin/perl -w + +use CGI::FormBuilder; +use utf8::all; + +# TODO: check if protocol-agnostic URL works +my $webroot_url = 'http://byvandring.nu/feedback/'; +my $webroot_path = '/home/bynu/public_websites/byvandring.nu/feedback'; +my $req_path = $webroot_path . '/index.html'; +my $ack_path = $webroot_path . '/tak/index.html'; + +# 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 => 'da', + title => 'Feedback til Byvandring.nu', + method => 'POST', + fields => [qw/ + kommentar + postnummer + email + /], + validate => { + postnummer => INT, + email => $valid_email, + _email => $valid_email, #fake check to silence warning of variable used only once + }, +# required => [qw/ +# email +# /], + messages => ':da_DK', + submit => ['Send oplysningerne'], + action => $webroot_url, #avoids loosing submitted values when redirected from other site +); + +$form->field( + name => 'postnr', + label => 'Postnummer', + size => 5, + comment => '(hvis du har lyst)' +); +$form->field( + name => 'kommentar', + type => 'textarea', + rows => 3, +); + +my ($form_required_text) = $form->{opt}{messages}{form_required_text}; +my ($mail_from) = $form->field('email') || undef; +my ($mail_to, $mail_subject); + +if ($form->submitted) { + $infostring = "Tak for din feedback!"; + if ($form->validate) { +# $mail_to = 'info@byvandring.nu'; + $mail_to = 'siri@jones.dk'; + $mail_subject = 'Feedback til Byvandring.nu'; + } else { +# $mail_to = 'siri@jones.dk, info@byvandring.nu'; + $mail_to = 'siri@jones.dk'; + $mail_subject = 'FEJL ved feedback til Byvandring.nu'; + $infostring .= "\n<P>OBS! Der var fejl i et eller flere af felterne. Informationerne er sendt uanset, men det anbefales at gå tilbage, checke at alle felter er udfyldt korrekt, og derefter sende igen."; + $confirm = 0; + }; +# if ($form->field('email')) { +# $infostring .= "\n<P>Der er sendt en kopi af tilmeldingen til " . $form->field('email') . "."; +# $mail_to .= ', ' . $form->field('email'); +# } + # 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: " . $form->field('brugergruppe_navn'), + subject => "$mail_subject", + ); + if ($confirm) { + $infostring .= "\n<P>Følgende informationer er blevet sendt:"; + $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 + ); +} |