Shortcodes are not executed in field values (the mayhem that could cause…).
To dynamicaly set a field value look at the Other Notes page for the field value filter. There are code examples there as well.
Hey Nick
Very much appreciated – I was just working through as I found that example. I have a form with the ID: 2. So in my functions.php I’ve put the following:
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_referrer_example', 10, 3 );
function salesforce_w2l_field_value_referrer_example( $val, $field, $form ){
$form_id = 2; // form id to act upon
$field_name = 'Remote_Addr__c'; // API Name of the field you want to autofill
if( $form == $form_id && $field_name == $field ){
if( isset( $_SERVER['REMOTE_ADDR'] ) ){
return $_SERVER['REMOTE_ADDR'];
}
}
return $val;
}
I had based this code off your examples you kindly pointed out (helpful as i’m really new to development). The form id is 2, and the field “Remote_Addr__c” is one I have in my salesforce:
Eg: http://screencast.com/t/bbmJmOmJry
The only part of this i don’t think i fully understand which i’m not sure if its impacting it is this:
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_referrer_example', 10, 3 );
I’m not sure if 10, 3 needs to be changed to something… or perhaps something else…
Are you able to point me in the right direction as i’ve cleared all my cache and can’t seem to get this darn ip stored which would be sooo helpful to me.
Thanks!
10 is the filter priority, 3 is the number of arguments to pass. So that doesn’t need to change.
Did you create a hidden field called Remote_Addr__c in your form?
Does $_SERVER[‘REMOTE_ADDR’] exist and have a value?
http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
Thanks i was missing it in the form and thought it would just be passed some how 😉 lol thanks again, love how its working.
Hello,
I have a need to now have this ip address capture on another form, so can I replace the line above with something like this?
(so it works on form 2 and 3)?
$form_id = 2,3; // form id to act upon
Thanks for your help!
-
This reply was modified 9 years, 6 months ago by
trader88888.
This will work for multiple forms:
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_value_referrer_example', 10, 3 );
function salesforce_w2l_field_value_referrer_example( $val, $field, $form ){
$form_ids = array( 2, 3 ); // form id to act upon
$field_name = 'Remote_Addr__c'; // API Name of the field you want to autofill
if( in_array( $form, $form_ids ) && $field_name == $field ){
if( isset( $_SERVER['REMOTE_ADDR'] ) ){
return $_SERVER['REMOTE_ADDR'];
}
}
return $val;
}