<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>
<?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;
?>