How to place the petition on my website

110 views
Skip to first unread message

Yannick Michel

unread,
Feb 23, 2016, 3:28:32 AM2/23/16
to Change.org API
Hi,
Yesterday I created a petition on change.org and I would love to let people sign it on the website of the organization.
I have a form on my page
<form name="htmlform" method="post" class="peThemeContactForm contact-form" action="sign_petition.php">
 
<h1><?php $content->title(); ?></h1>
 
<input type="text" name="name" class="required" placeholder="Nom" required />
                   
<input type="text" name="firstname" class="required" placeholder="Prénom" required />
 
<input type="email" name="email" class="required" placeholder="E-Mail" data-validation="email" required />
 
<select name="country" class="required" placeholder="Where do you come from?">
 
<?php get_template_part("countries");?>
 
</select>
                   
<input type="text" name="city" class="required" placeholder="Ville" required />
 
<textarea name="message" cols="1" rows="5" placeholder="Je signe pour..." required ></textarea>
 
<input name="send" type="submit" class="submit" value="Je Signe" />
 
<!--alert success-->
 
<div id="contactFormSent" class="formSent fade in hide">
 
<?php echo $contact->msgOK; ?>
 
</div>
 
 
<!--alert error-->
 
<div id="contactFormError" class="formError fade in hide">
 
<?php echo $contact->msgKO; ?>
 
</div>
 
</form>

the action of the form is sign_petition.php

<?php
 
// Set my API key and secret token.
  $api_key
= 'fe1a72b3c7ae9adc5706ef078cbd76ee89bc765890dcc72c9d3711c818c0XXXX';
  $secret
= '8b5671face76f12634f574ce47c176b10b6dab3cfa409a088c065ff9999dXXXX';
 
// Set my authorization key for petition with Change.org ID 6199546.
  $petition_auth_key
= '59e2b5bf2aa5e7f13eaab1cd5cd23b0be10db70211378bb6841b19f57a74XXXX';
  $petition_id
= 6199546;
 
// Set up the endpoint and URL.
  $base_url
= "https://api.change.org";
  $endpoint
= "/v1/petitions/$petition_id/signatures";
  $url
= $base_url . $endpoint;
 
// Set up the signature parameters.
  $parameters
= array();
  $parameters
['api_key'] = $api_key;
  $parameters
['timestamp'] = gmdate("Y-m-d\TH:i:s\Z"); // ISO-8601-formtted timestamp at UTC
  $parameters
['endpoint'] = $endpoint;
  $parameters
['source'] = 'http://XXXX:8888/visahumanitaire/#petition';
  $parameters
['email'] = $_POST['email'];
  $parameters
['first_name'] = $_POST['firstname'];
  $parameters
['last_name'] = $_POST['name'];
  $parameters
['city'] = $_POST['city'];
  $parameters
['country_code'] = $_POST['country'];
 
// Build request signature.
  $query_string_with_secret_and_auth_key
= http_build_query($parameters) . $secret . $petition_auth_key;
 
 
// Add the request signature to the parameters array.
  $parameters
['rsig'] = hash('sha256', $query_string_with_secret_and_auth_key);
 
// Create the request body.
  $data
= http_build_query($parameters);
 
// POST the parameters to the petition's signatures endpoint.
  $curl_session
= curl_init();
  curl_setopt_array
($curl_session, array(
    CURLOPT_POST
=> 1,
    CURLOPT_URL
=> $url,
    CURLOPT_POSTFIELDS
=> $data
 
));
  $result
= curl_exec($curl_session);
 
// Output  the returned JSON result.
  echo $result
;
?>
And nothing happens when I test my form.
Can anyone help me with this one?
I'm not very familiar with this

Yannick Michel

unread,
Feb 25, 2016, 3:22:24 AM2/25/16
to Change.org API
What was blocking me was in fact the theme I used in wordpress. The form wasn't sending the information to my sign_petition.php. Now it works, I just wonder how I could create a success message once the signature is sent and show the share links for facebook and twitter. Any of you have already done this? Is there any easy way to do it?
Reply all
Reply to author
Forward
0 new messages