Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • jpiper.kmi

    (@jpiperkmi)

    Thanks for the suggestion. I believe I’ve got it working.
    (see updated code below)

    add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_querystring_insert', 10, 3 );
    function salesforce_w2l_field_value_querystring_insert( $val, $field, $form ){
    
    	// API Name of the field your want to autofill
    	$field_name_source = 'SEO_Source__c';
    	$field_name_medium = 'SEO_Medium__c';
    	$field_name_campaign = 'SEO_Campaign__c';
    	$field_name_content = 'SEO_Content__c';
    	$field_name_term = 'SEO_Term__c';
    
    	$qs_var_source = 'utm_source'; // e.g. ?utm_source=google
    	$qs_var_medium = 'utm_medium'; // e.g. ?utm_medium=ppc
    	$qs_var_campaign = 'utm_campaign'; // e.g. ?utm_campaign=brand
    	$qs_var_content = 'utm_content'; // e.g. ?utm_content=topCTA
    	$qs_var_term = 'utm_term'; // e.g. ?utm_term=foo
    
    	if( $field_name_source == $field ){
    		if( isset( $_GET[ $qs_var_source ] ) ){
    			return $_GET[ $qs_var_source ];
    		}
    		else {};
    	}
    	if( $field_name_medium == $field ){
    		if( isset( $_GET[ $qs_var_medium ] ) ){
    			return $_GET[ $qs_var_medium ];
    		}
    		else {};
    	}
    	if( $field_name_campaign == $field ){
    		if( isset( $_GET[ $qs_var_campaign ] ) ){
    			return $_GET[ $qs_var_campaign ];
    		}
    		else {};
    	}
    	if( $field_name_content == $field ){
    		if( isset( $_GET[ $qs_var_content ] ) ){
    			return $_GET[ $qs_var_content ];
    		}
    		else {};
    	}
    	if( $field_name_term == $field ){
    		if( isset( $_GET[ $qs_var_term ] ) ){
    			return $_GET[ $qs_var_term ];
    		}
    		else {};
    	}
    	if ($vals >= $val){return $vals;} else{return $val;};
    
    }
    jpiper.kmi

    (@jpiperkmi)

    Thanks for the quick reply! I’m certainly not to proud to admit I might have a bug. (See below for code.) I customized this in hopes to apply it to any form on the site, but only for the specific fields listed as variables.

    add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_querystring_example', 10, 3 );
    function salesforce_w2l_field_value_querystring_example( $val, $field, $form ){
    
    	// API Name of the field your want to autofill
    	$field_name_source = 'SEO_Source__c';
    	$field_name_medium = 'SEO_Medium__c';
    	$field_name_campaign = 'SEO_Campaign__c';
    	$field_name_content = 'SEO_Content__c';
    	$field_name_term = 'SEO_Term__c';
    
    	$qs_var_source = 'utm_source'; // e.g. ?utm_source=google
    	$qs_var_medium = 'utm_medium'; // e.g. ?utm_medium=ppc
    	$qs_var_campaign = 'utm_campaign'; // e.g. ?utm_campaign=brand
    	$qs_var_content = 'utm_content'; // e.g. ?utm_content=topCTA
    	$qs_var_term = 'utm_term'; // e.g. ?utm_term=foo
    
    	if( $field_name_source == $field ){
    		if( isset( $_GET[ $qs_var_source ] ) ){
    			return $_GET[ $qs_var_source ];
    		}
    		else {};
    	}
    	if( $field_name_medium == $field ){
    		if( isset( $_GET[ $qs_var_medium ] ) ){
    			return $_GET[ $qs_var_medium ];
    		}
    		else {};
    	}
    	if( $field_name_campaign == $field ){
    		if( isset( $_GET[ $qs_var_campaign ] ) ){
    			return $_GET[ $qs_var_campaign ];
    		}
    		else {};
    	}
    	if( $field_name_content == $field ){
    		if( isset( $_GET[ $qs_var_content ] ) ){
    			return $_GET[ $qs_var_content ];
    		}
    		else {};
    	}
    	if( $field_name_term == $field ){
    		if( isset( $_GET[ $qs_var_term ] ) ){
    			return $_GET[ $qs_var_term ];
    		}
    		else {};
    	}
    	return $vals;
    
    }
    jpiper.kmi

    (@jpiperkmi)

    I believe I found a bug in which this script seems to erase the values out of all the other hidden fields in the form. I’m trying to both set a hidden field value with the query-string and also hard code a different hidden field with a value in the basic form editor.

    Any ideas?

    Thread Starter jpiper.kmi

    (@jpiperkmi)

    Correction. The code above appears to work to input the value into a field called retURL, but it appears that it doesn’t have any impact on the URL the form is being directed to after submission.

    Thread Starter jpiper.kmi

    (@jpiperkmi)

    I’m testing this out now, but still no luck. Are the opening/closing {} correct in this code? My text editor doesn’t seem to find the matches, so updated it to the following (still no luck though).

    add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_urlredirect', 10, 3 );
    function salesforce_w2l_field_urlredirect( $val, $field, $form ){
    
    	$postid = get_the_id();
    
    	// Target a specific field on all forms
    	if( $field == 'retURL' ){
    
    		if( $field == 'retURL' && $postid == '671' )
    			 $URL =  'http://www.mycompany.com/thank-you?option=1' ;
    		else if( $field == 'retURL' && $postid == '669' )
    			 $URL =  'http://www.mycompany.com/thank-you?option=2' ;
    		else if ( $field == 'retURL' && $postid == '360' )
    			 $URL =  'http://www.mycompany.com/thank-you?option=3' ;
    		}
    
      	if( $URL ){
    			$val = $URL;
      	}
    	return $val;
    }
Viewing 5 replies - 1 through 5 (of 5 total)