Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nciske/29ecd457e14b6aec54e36bac59ab78ed to your computer and use it in GitHub Desktop.
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)
<?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