PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Capture http referrer url in hidden field

  1. I wish to capture the url of the referring url prior to landing on the form page.

    I note that there is a merge field called 'embed url' but oddly no 'referral url' which I would think would be a standard, powerful feature of Gravity forms?

    This suggests there is some additional coding / jquery to do in the headers etc which I am reluctant to do :)

    Can anyone provide a step-by-step dummy proof mechanism to capture the referral url in my existing form without jumping through too many hoops?

    Thanks so much
    J

    Posted 10 years ago on Wednesday May 16, 2012 | Permalink
  2. David Peralty

    Hi J,

    So there are a few simple steps that I can help you with.

    FORM SET-UP
    You will need a field to put in the referrer URL so that it gets saved to the entries table in Gravity Forms.

    1. Create a Hidden Field in your Form. (Hidden FIelds are in the Standard Fields set)
    2. Give it a label (Ref URL) - The label isn't important but helpful
    3. Under the Advanced Tab, click the check box for Allow Field to be Populated Dynamically
    4. Give it a Parameter Name (refurl)

    FUNCTIONS.PHP Changes
    You will need to create a function to grab the referrer URL and pass it to the hidden field.

    #1 - In your theme's function.php file you will need to create a filter using the gform_field_value_$parameter_name hook: http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    It will look like the following:

    add_filter("gform_field_value_refurl", "referral_url");

    As you can see, I used the parameter name that I put in above (refurl).

    #2 - Next we will need to code the referral_url function to grab the URL and then put it into the hidden field.

    function referral_url($form){
    	//Grab URL from HTTP Server Var and put it into a variable
    	$refurl = $_SERVER['HTTP_REFERER'];
    
    	//Return that value to the form
    	return esc_url_raw($refurl);
    }

    FINAL NOTES
    Now, if everything has been done correctly, when the form is loaded, the function will be called to grab the referral page and put the value into a hidden field. Then when you look at your entries, you should see which page lead them to your form.

    Posted 10 years ago on Wednesday May 16, 2012 | Permalink
  3. Thanks so much for the quick reply! I will give this go and revert back to you.....I appreciate the step-by-step approach!

    Posted 10 years ago on Wednesday May 16, 2012 | Permalink
  4. David,

    I tried implementing this with ZOHO CRM. Looks like, when adding the HIdden Field to your form you may have to also select "HTTP Refererl URL" under Insert Merge Tag dropdown.

    Is this correct?

    Posted 9 years ago on Wednesday June 13, 2012 | Permalink
  5. David Peralty

    vmanepete - If you set the default value to be the HTTP Ref URL, then you shouldn't need to do what I listed above. Though double check that it gets picked up properly and sent along.

    Posted 9 years ago on Wednesday June 13, 2012 | Permalink