This script emulates the old EN API but stores petition signups outside Engaging. You can store petition data in BigQuery, SQlite or MySQL (For example Google Cloud SQL).
This script is useful if you have legacy petitions and need to have them running in 2019 without changing the code to the new API. With this script, in your old petitions, you might just need to change the receiving URL from https://e-activist.com/ea-action/action
to the receiving URL your PHP server.
Please note this script was developed for the Spanish Office, so it will need small adjustments before it can be used by other NROs. If you use it, you’ll need to manually export the signups to your CRM or mailing app.
Important: To adapt this script to your field names, modify index.php
in this repository. Please note you'll need to adjust your database fields as well.
Download this script with Git:
git clone https://github.com/greenpeace/gpes-old-en-petitions-api-emulator.git
Get Composer and download the required libraries with the command:
curl -sS https://getcomposer.org/installer | php
php composer.phar install
To store the signups you can use Bigquery, SQLite or MySQL. See how to:
- Configure Google Cloud and Big Query
- Configure SQLite
- Configure MySQL - For example for Google Cloud SQL
Follow the instructions in one of the the links above and then continue bellow.
Now that you have configured your script and your database you can upload the files and folders:
index.php
config.php
src/
testing/
The vendor
folder, downloaded with composer, should be uploaded as well.
- With your browser, visit testing/js.html in your server.
- Confirm there's data in your new petitions database.
- Test the html form redirection by submitting the form in testing/html.html.
- Confirm again that your last form test is in the database.
If you use BigQuery, you can check your database with the query:
#standardSQL
SELECT * FROM `gpes_en_old_api.signups` ORDER BY signed_time;
If you use SQLite you can download your database file and open it in your computer with an SQLite client. Or you can install Adminer on your server.
And if you use MySQL you can use a client like for example Sequel Pro to access your data or a server-side script like Adminer.
In your forms change the URL that receives petition's data from https://e-activist.com/ea-action/action
to equivalent URL in your PHP server. It should be the script's index.php
file or it's parent folder.
Normally you should do this twice: in the html and in the javascript. For more information check testing-html-html and testing-js.html.