Description
This filter can be used to modify the lead arguments before they are sent to Zoho CRM.
Usage
The following would apply to all feeds:
add_filter( 'gform_zohocrm_lead', 'your_function_name', 10, 4 );
To target feeds for a specific form append the form id to the hook name. (format: gform_zohocrm_lead_FORMID)
add_filter( 'gform_zohocrm_lead_4', 'your_function_name', 10, 4 );
Parameters
- $lead array
The lead arguments are an associative array.
array( 'Email Opt Out' => 'false', 'Description' => 'some text', 'Lead Source' => 'Advertisement', 'Lead Status' => 'Not Contacted', 'Rating' => 'Acquired', 'SMOWNERID' => 'The-Zoho-CRM-User-ID-Here', 'options' => array( 'duplicateCheck' => '1', 'isApproval' => 'false', 'wfTrigger' => 'false' ), )
The feed currently being processed.
The entry currently being processed.
The form currently being processed.
Examples
1. Change Email Opt Out
This example shows how you can change the ‘Email Opt Out’ setting based on a field value in the Entry Object.
add_filter( 'gform_zohocrm_lead_4', 'change_lead_argument', 10, 4 ); function change_lead_argument( $lead, $feed, $entry, $form ) { if ( rgars( $feed, 'meta/feedName') == 'Zoho CRM Feed 2' && rgar( $entry, '5' ) == 'No' ) { $lead['Email Opt Out'] = 'true'; } return $lead; }
2. Set Owner based on country
add_filter( 'gform_zohocrm_lead_9', 'change_lead_argument', 10, 4 ); function change_lead_argument( $lead, $feed, $entry, $form ) { if ( rgars( $feed, 'meta/feedName' ) == 'Zoho Sales Inquiry' ) { // get the selected country from field 4 $country = rgar( $entry, '4' ); // define an array containing the countries and the zoho crm id to be used for that country $owners = array( 'Afghanistan' => 'The-Zoho-CRM-User-ID-Here', 'Albania' => 'The-Zoho-CRM-User-ID-Here', ); // replace the feed configured owner with the id by using the $country as the key to the value in the $owners array $lead['SMOWNERID'] = rgar( $owners, $country ); } return $lead; }
3. Set the Layout
This example shows how you can define the Layout the lead should use for a specific feed of form 4.
add_filter( 'gform_zohocrm_lead_4', function( $lead, $feed, $entry, $form ) { if ( rgars( $feed, 'meta/feedName') == 'Zoho CRM Feed 2' ) { $lead['Layout'] = array( 'name' => 'the layout name here', 'id' => 'the layout id here' ); } return $lead; }, 10, 4 );
4. Preserve Lead Source on Update
This example shows how you can preserve any existing Lead Source in Zoho for all feeds on form 33.
add_filter( 'gform_zohocrm_lead_33', function( $lead, $feed, $entry, $form ) { unset( $lead['Lead_Source'] ); return $lead; }, 10, 4 );
5. Add the $gclid parameter
This example shows how to get the value from a Hidden field of a form, where dynamic population has been enabled and gclid used as the Parameter Name, and pass it to Zoho CRM as value for $gclid
add_filter( 'gform_zohocrm_lead', function( $lead, $feed, $entry, $form ) { gf_zohocrm()->log_debug( 'Adding $glid parameter...' ); foreach ( $form['fields'] as &$field ) { // Your hidden field must use gclid (case sensitive) as the Parameter Name for dynamic population. if ( 'gclid' === $field->inputName ) { $lead['$gclid'] = rgar( $entry, $field->id ); gf_zohocrm()->log_debug( '$glid set to: ' . $lead['$gclid'] ); } } return $lead; }, 10, 4 );
6. Use a field value for Lead Description
By default the Lead Description can be set manually in your feed settings. The following example shows how it can be set using a value from a field in your form where you have set zohocrm_lead_description as the field Admin Field Label.
add_filter( 'gform_zohocrm_lead', function( $lead, $feed, $entry, $form ) { gf_zohocrm()->log_debug( 'Adding custom Lead Description from a field...' ); foreach ( $form['fields'] as &$field ) { // Your field must use zohocrm_lead_description (case sensitive) as the Admin Field Label. if ( 'zohocrm_lead_description' === $field->adminLabel ) { $lead['Description'] = rgar( $entry, $field->id ); gf_zohocrm()->log_debug( 'Description set to: ' . $lead['Description'] ); } } return $lead; }, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_zohocrm_lead', $form['id'], $lead, $feed, $entry, $form )
This filter is located in GFZohoCRM::create_lead() in class-gf-zohocrm.php.