x
 
Create New Page
 View Previous Changes    ( Last updated by moresided )

A simple petition

Instructions for making a simple petition that captures users’ details, confirms their entry via email, then displays the list of entries that have been confirmed.

This method avoids having to edit the member templates, which are difficult to manage. Instead it uses a combination of the mailing list module and Solspace’s free Freeform module to manage storing the data and confirming users’ emails.

Method:

1. Download Solspace’s Freeform module and install.
2. Create a mailing list - I called mine ‘petition’
3. Create a template for your petition form, for example in petition/index and use something like this for the Freeform start tag:

{exp:freeform:form form_name="petition" return="petition/thanks" required="first_name|last_name|email" prevent_duplicate_on="email" mailinglist="petition" mailinglist_opt_in="yes"}

See the Freeform documentation for more information.

The idea is that users who enter their details automatically receive an email asking them to confirm - this is sent by the mailing list module. When they click the link in the email they get added to the mailing list. Their details like name, country etc are saved into the freeform module.

4. Edit your email confirmation in Admin->Specialty Templates->Email Notification templates->Mailing List Activation Instructions to say that you are confirming your entry in the petition.

5. Create a ‘Thanks’ page (for example in petition/thanks) to remind people to check their email. This is the page people go to after they’ve filled in the form, as defined in the Freeform start tag:  return="petition/thanks"

6. To display a list only of people who have confirmed their email address, use an SQL query to match Freeform entries to people who have confirmed their email and as such been added to the mailing list. For example:

{exp:query sql="SELECT exp_freeform_entries.first_name as ‘first_name’,exp_freeform_entries.last_name as ‘last_name’,exp_freeform_entries.country as ‘country’,exp_freeform_entries.entry_date as ‘entry_date’ FROM exp_freeform_entries, exp_mailing_list WHERE exp_freeform_entries.email = exp_mailing_list.email ORDER BY exp_freeform_entries.entry_id DESC"}

As you can see, only entries which match email to email will be shown.

7. As an extra touch, use a PHP counter to show the number of each person who has signed the petition:

<?php $total_results = {total_results}+1;
$count = {count};?>

And then on each row:
<?php echo ($total_results - $count); ?>