summaryrefslogtreecommitdiff
path: root/vejviseren
diff options
context:
space:
mode:
authorSiri Reiter <siri@jones.dk>2021-01-15 19:24:12 +0100
committerSiri Reiter <siri@jones.dk>2021-01-15 19:24:12 +0100
commit4f456b3285184b7e68d65ce61bb595631b13cde8 (patch)
treebdcdf6eecb7c0d81debc5d042e5ed0f337a27142 /vejviseren
parent0e2d79fb02554d5a638de0a93e21429e1a5c6e68 (diff)
Add form CGI.
Diffstat (limited to 'vejviseren')
-rwxr-xr-xvejviseren/familieture.cgi131
1 files changed, 131 insertions, 0 deletions
diff --git a/vejviseren/familieture.cgi b/vejviseren/familieture.cgi
new file mode 100755
index 0000000..1d7dd97
--- /dev/null
+++ b/vejviseren/familieture.cgi
@@ -0,0 +1,131 @@
+#!/usr/bin/perl -w
+
+use CGI::FormBuilder;
+
+my $build_path = '../build';
+
+# TODO: check if protocol-agnostic URL works
+my $webroot = 'https://byvandring.nu/vejviseren/familieture/';
+my $req_path = $build_path . '/html/vejviseren/familieture/index.html';
+my $ack_path = $build_path . '/html/vejviseren/familieture/tak/index.html';
+
+my $webmaster = 'info@byvandring.nu';
+my $frontdesk = 'info@byvandring.nu';
+my $helpdesk = 'siri@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 => 'da',
+ title => 'Henvendelse til Byvandring.nu',
+ method => 'POST',
+ fields => [qw/
+ navn
+ org
+ postnr
+ email
+ tur
+ antal
+ tid
+ kommentar
+ /],
+ validate => {
+ 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, #avoids loosing submitted values when redirected from other site
+);
+
+$form->field(
+ name => 'navn',
+ label => 'Navn',
+ comment => '(dit eget navn)'
+);
+$form->field(
+ name => 'org',
+ label => 'Firma/ skole',
+ comment => '(hvem du repræsenterer)'
+);
+$form->field(
+ name => 'postnr',
+ label => 'Postnummer',
+ size => 5,
+ comment => '(hvis du har lyst)'
+);
+$form->field(
+ name => 'tur',
+ label => 'Tur',
+ size => 5,
+ comment => '(turnavn, bydel eller tema)'
+);
+$form->field(
+ name => 'antal',
+ label => 'Antal',
+ size => 5,
+ comment => '(antal deltagere)'
+);
+$form->field(
+ name => 'tid',
+ label => 'Tidspunkt',
+ size => 5,
+ comment => '(dato og tidspunkt)'
+);
+$form->field(
+ name => 'kommentar',
+ 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 = "Tak for din henvendelse!";
+ if ($form->validate) {
+ $mail_to = $frontdesk;
+ $mail_subject = 'Henvendelse til Byvandring.nu';
+ } else {
+ $mail_to = "$frontdesk, $helpdesk";
+ $mail_subject = 'FEJL ved henvendelse 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;
+ };
+ # 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<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
+ );
+}