Browse Source

merged test versions of petition page to include form submission process

svn path=/trunk/; revision=16903
samtuke 11 years ago
3 changed files with 206 additions and 6 deletions
  1. +98
  2. +85
  3. +23

+ 98
- 6
campaigns/pdfreaders/petition.en.xhtml View File

@ -35,16 +35,108 @@
<p>The Undersigned</p>
<hr />
<p><em>To sign the petition, email <a href=" Sign The Petition"></a>. </em>We update the list of signatories several times a day, so please allow some time for your signature to appear.</p>
<h2>List of signatories</h2>
<form action="/cgi-bin/" method="post">
<label for="name">Name <span class="required-asterisk">*</span></label>
<input id="name" name="name" type="text" />
<label for="surname">surname <span class="required-asterisk">*</span></label>
<input id="surname" name="surname" type="text" />
<label for="email">Your E-mail <span class="required-asterisk">*</span></label>
<input id="email" name="email" type="email" />
<label for="email">On Belhalf of</label>
<input id="group" name="group" type="text" />
<label for="country">Country of the institution (in English) <span class="required-asterisk">*</span></label>
<select id="country" name="country">
<option>Bosnia and Herzegovina</option>
<option>Czech Republic</option>
<option>Faroe Islands</option>
<option>Russian Federation</option>
<option>United Kingdom</option>
<label>Receive Newsletter</label>
<input name="newsletter" type="checkbox" checked="checked" />
<p class="n">
<label for="url">If you're a bot please enter something here to have our system happily ignore all of your efforts</label>
<input id="url" name="url" type="text" />
<input type="submit" value="Sign Petition" />
<hr />
<p><em>We update the list of signatories several times a day, so please allow some time for your signature to appear.</em></p>
<h2>List of signatories</h2>
<text id="osig">Organizations</text>
<text id="bsig">Businesses</text>
<text id="osig">Businesses</text>
<text id="bsig">Organizations</text>
<text id="isig">Individuals</text>
<timestamp>$Date: 2010-09-07 16:38:57 +0200 (Tue, 07 Sep 2010) $ $Author: maelle $</timestamp>

+ 85
- 0
cgi-bin/ View File

@ -0,0 +1,85 @@
#!/usr/bin/env perl
use 5.008;
PDFreaders petition form processing script.
=head1 AUTHOR
Sam Tuke <>, extending Alexander Kahl <>
use Cwd qw (abs_path);
use File::Basename qw (dirname);
my $root;
BEGIN { $root = abs_path (dirname (__FILE__).'/..') };
use lib "$root/tools";
use CGI;
use DateTime;
use Template;
use WebBuild::FormValidation;
use WebBuild::DynamicContent;
use strict;
use warnings;
use constant TEMPLATE => "$root/templates/pdfreaders-petition-mail.tt2.xml";
use constant UPLOAD => "$root/upload/pdfreaders";
# Start actual logic
my $form = WebBuild::FormValidation->new;
my $content = WebBuild::DynamicContent->new;
my $query = CGI->new;
$content->layout ("$root/campaigns/pdfreaders/petition.en.html");
$form->validates_presence_of ('name');
$form->validates_presence_of ('surname');
$form->validates_presence_of ('country');
$form->validate_format ('email', type => 'email');
if ($form->has_errors)
$content->content ($form->get_errors);
elsif ($query->param ('url')) # Bot!!
# Record data here
my $template = Template->new ({ INCLUDE_PATH => "$root/templates" });
my $mail;
my $dt = DateTime->now;
my $data = { country => $query->param ('country'),
date => sprintf ('%d-%.2d-%.2d', $dt->year, $dt->month, $dt->day),
name => $query->param ('name'),
surname => $query->param ('surname'),
email => $query->param ('email'),
group => $query->param ('group') || '',
newsletter => $query->param ('newsletter') };
$template->process ('pdfreaders-petition-mail.tt2', $data, \$mail);
open MAIL, "|/usr/lib/sendmail -t";
print MAIL $mail;
close MAIL;
my $output = <<'EOF';
<div id="flash">
<p>Thank you for signing - your signature has been recorded, and will be added shortly.</p>
$content->content ($output);

+ 23
- 0
templates/pdfreaders-petition-mail.tt2 View File

@ -0,0 +1,23 @@
MIME-Version: 1.0
Subject: [PDFReaders] petition signature
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
A new PDFReaders petition signature has been submitted.
Please validate and use the following XML snippet if appropriate:
name="[% name %]"
surname="[% surname %]"
email="[% email %]"
group="[% group %]"
country="[% country %]"
nl=[[% IF newsletter %]X[% ELSE %] [% END %]]
date="[% date %]"