Last active
March 25, 2017 03:01
-
-
Save nciske/29ecd457e14b6aec54e36bac59ab78ed to your computer and use it in GitHub Desktop.
Autofill fields based on the query string (using Google Analytics tracking variables in this example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Autofill fields based on the query string (using Google Analytics tracking variables in this example) | |
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_querystring_multiple_example', 10, 3 ); | |
function salesforce_w2l_field_value_querystring_multiple_example( $val, $field, $form ){ | |
$form_id = 1; // form id to act upon | |
if( $form != $form_id ){ | |
return $val; | |
} | |
// key = API Name of the field you want to autofill - you have to create these custom fields at Salesforce first! | |
// val = Query string variable to grab - e.g. ?source=foo | |
// Add lines as needed | |
$map = array( | |
'utm_source__c' => 'utm_source', | |
'utm_medium__c' => 'utm_medium', | |
'utm_campaign__c' => 'utm_campaign', | |
'utm_term__c' => 'utm_term', | |
'utm_content__c' => 'utm_content', | |
); | |
foreach( $map as $field_name => $qs_var ){ | |
if( $field_name == $field ){ | |
if( isset( $_GET[ $qs_var ] ) ){ | |
return $_GET[ $qs_var ]; | |
} | |
} | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment