• Resolved trader88888

    (@trader88888)


    Hello,

    I tried setting up a function with a shortcode that works [show_ip] but when I put this into the value of a field in the plugin you created, all i get into salesforce is [show_ip] and not the actual ip address x.x.x.x

    Do you know how I can fix this or any other way to get the users IP into that field using your web to lead form?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Nick Ciske

    (@nickciske)

    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.

    Thread Starter trader88888

    (@trader88888)

    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: https://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!

    Plugin Author Nick Ciske

    (@nickciske)

    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?

    https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php

    Thread Starter trader88888

    (@trader88888)

    Thanks i was missing it in the form and thought it would just be passed some how ?? lol thanks again, love how its working.

    Thread Starter trader88888

    (@trader88888)

    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!

    Plugin Author Nick Ciske

    (@nickciske)

    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;
    
    }
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Storing IP Address’ is closed to new replies.