/*gravity form data send */
add_action( 'gform_after_submission', 'access_entry_via_field', 10, 2 );
function access_entry_via_field( $entry, $form ) {
// store data in txt file
$leadFormEntryInput = json_encode($entry);
//parameter zoho
$formID = filter_var($entry['form_id'], FILTER_SANITIZE_STRING);
if($formID === '6'){
$name = filter_var($entry['3'], FILTER_SANITIZE_STRING);
$phone = filter_var($entry['9'], FILTER_SANITIZE_STRING);
$email = filter_var($entry['5'], FILTER_SANITIZE_STRING);
$message = filter_var($entry['7'], FILTER_SANITIZE_STRING);
}else {
if(!isset($entry[1]) ){
$name = filter_var($entry['1.3'], FILTER_SANITIZE_STRING);
}else{
$name = filter_var($entry['1'], FILTER_SANITIZE_STRING);
}
$phone = filter_var($entry['3'], FILTER_SANITIZE_STRING);
$email = filter_var($entry['4'], FILTER_SANITIZE_STRING);
$message = filter_var($entry['5'], FILTER_SANITIZE_STRING);
}
$ip = filter_var($entry['ip'], FILTER_SANITIZE_STRING);
$sourceURL = filter_var($entry['source_url'], FILTER_SANITIZE_STRING);
$dateCreate = filter_var($entry['date_created'], FILTER_SANITIZE_STRING);
// push zoho code
$client_id = '1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$refresh_token = '1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$url = "https://accounts.zoho.in/oauth/v2/token?refresh_token=$refresh_token&client_id=$client_id&client_secret=$client_secret&grant_type=refresh_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$output = json_decode($result, true);
$access_token = $output['access_token'];
$url = "https://www.zohoapis.in/crm/v2/Leads/upsert";
$header = array("Authorization: Zoho-oauthtoken $access_token");
$json = array(
"data" => array(
array(
"Company" => 'Company Name',
"Last_Name" => $name,
"Email" => $email,
"Source" => 'NA',
"Medium" => 'NA',
"Campaign" => 'NA',
"Landing_Page" => $sourceURL,
"Lead_Source" => 'Web',
"Mode_of_Lead" => 'Web-form',
"IP" => $ip,
"Google_Client_ID" => 'NA',
"Phone" => $phone
)
)
);
$json_data = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/* gravity form data send */
Gravity form predefined function gform_after_submission is executed at the end of form submission process when user submit the form.
Gravity form gform_after_submission function contact entry object parameter contains all submitted values by user in form.
Placement of Gravity form function
Above function place in functions.php file of current active theme.
Parameters of gform_after_submission
$entry and $form
Entry Object : Entry object contains all properties of a particular entry. It is formatted as an associative array with field Ids being the key to that field’s data.
$entry JSON Code Example
{
"3": "myfreeonlinetools",
"5": "[email protected]",
"7": "myfreeonlinetools",
"9": "9879879876",
"10": "+91",
"id": "215",
"status": "active",
"form_id": "6",
"ip": "165.225.124.239",
"source_url": "https://myfreeonlinetools.com/",
"currency": "USD",
"post_id": null,
"date_created": "2024-04-23 09:10:15",
"date_updated": "2024-04-23 09:10:15",
"is_starred": 0,
"is_read": 0,
"user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/124.0.0.0 Safari\/537.36",
"payment_status": null,
"payment_date": null,
"payment_amount": null,
"payment_method": "",
"transaction_id": null,
"is_fulfilled": null,
"created_by": "19",
"transaction_type": null
}
Form Object : The form object, available to most action hooks and filters, is an associative array containing the form settings, fields, notifications, confirmations, and other properties.