Skip to content

Instantly share code, notes, and snippets.

@zaheeraws
Last active April 3, 2019 10:49
Show Gist options
  • Save zaheeraws/3e2b87c648ab38e85b02c756357d6817 to your computer and use it in GitHub Desktop.
Save zaheeraws/3e2b87c648ab38e85b02c756357d6817 to your computer and use it in GitHub Desktop.
Submit (formcraft) forms information to iPlan | Wordpress plugin
<?php
/*
* Plugin Name: odeon-to-iPlan
* Description: Submit (Contact Form 7) forms information to iPlan
* Version: 1.0
* Author: fieztech <[email protected]>
* Author URI: https://feztech.com
*/
add_action('formcraft_after_save', 'ft_api_to_iPlan', 10, 4);
function ft_api_to_iPlan($content, $meta, $raw_content, $integrations)
{
$raw_content = json_decode( json_encode($raw_content) );
$fullname = "";
$email = "";
$phone = "";
$message = "";
foreach ($raw_content as $key => $value) {
if( $value->label == "Full name" || $value->identifier == "field1"){
$fullname = $value->value;
}elseif( $value->label == "Telephone" || $value->identifier == "field2" ){
$phone = $value->value;
}elseif( $value->label == "Email" || $value->identifier == "field3"){
$email = $value->value;
}elseif( $value->label == "Message" || $value->identifier == "field4"){
$message = $value->value;
}
}
$apiKey = "__ADD_API__KEY";
$url = 'https://iplan.co.il/he-IL/api/corp/leads.json';
$jsonData = array(
'api_key' => $apiKey,
'form_id' => 576,
'contact_full_name' => $fullname ,
'contact_email' => $email,
'request_content' => $phone . PHP_EOL . $message,
'request_matter' => "interested",
);
$ch = curl_init($url);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment