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.

How to capture the post ID of the referring page

  1. Hi,

    I have multiple motorcycle listings on my website, and for all of them I link to one contact form (using easy contact right now, which I have modified.) In any case, I would like to display the title of the Page when they land on the contact form (i.e. "Regarding: 2008 Specific Motorcycle") and I was doing that in the past by using WordPress queryvars. I'm trying to go from 3 form plugins down to one: I've already removed one, and Easy Contact is the other one.

    So, what is the best way to do what I need here: I would like the Gravity contact form, when they land on it, to know what Page the click came from, and then also send the URL of that page in the email notification.

    If none of that makes sense, see these pages for the way it works now:


    The "Request more information" link is a link to the contact form, and it looks like this:

    3676 is the ID of that Page. When that ID goes to the contact form, I can use queryvars and determine the URL (permalink) and the Title of the page (which is displayed above the form. Here's the code I use in functions.php:

    // add a query var for the postid to send to the contact form
    add_filter('query_vars', 'parameter_queryvars' );
    function parameter_queryvars( $qvars ) {
            $qvars[] = 'postid';
            return $qvars;

    and the modification to the Easy Contact plugin:

    // grab the postid if it was sent as a query var
    global $wp_query;
    if (isset($wp_query->query_vars['postid'])) {
    	$postID = $wp_query->query_vars['postid'];
    	$form .= "\n\t<p><strong>Regarding</strong>: " . get_the_title($postID) . "</p>";

    I'm sure I made this sound more complicated than it really is, and there's probably a really easy way to do this with GF that I have overlooked.

    I was using Joost's referrer plugin for GF, but that appended ALL the site visit history as referrers to the email notifications, and when employees respond to the contact, they don't always think to remove all that data, so the response to the customer has 20 or 50 or 300 URLs that they visited. Not cool. So, I stopped using that. If I can recreate what I have with Easy Contact now, using GF, I will dump yet another form plugin.

    If you want to test the Easy Contact form for some reason, please feel free to do so, just put TEST somewhere in the name fields.

    Hope that makes sense. Thank you.

    Posted 14 years ago on Thursday January 7, 2010 | Permalink
  2. You can accomplish what you want to do in two steps.

    1- Display the referrer post title in your form's description (assumes "postid" is passed in the querystring)

    //Adds post title to form description
    add_filter("gform_pre_render_18", "populate_description");
    function populate_description($form_meta){
        $form_meta["description"] = "Regarding: " . get_the_title($_GET["postid"]);
        return $form_meta;

    Note: You will need to replace _18 with your actual form id.

    2- Send the referrer URL in the notification
    You can do that by adding a hidden field to your form and populating it's default value (advanced tab) with the variable "HTTP Referrer URL"
    From there, you can select that hidden field as a variable in your notification emails like any other field.

    I think this is all you need. Let me know how it goes.
    Good Luck.

    Posted 14 years ago on Thursday January 7, 2010 | Permalink
  3. Worked brilliantly. I added a conditional to account for someone accessing the page with the embedded form directly (without the postid there), but other than that , this worked straight away. One more form plugin replaced by Gravity. Thanks

    Posted 14 years ago on Friday January 8, 2010 | Permalink
  4. Nice! Glad to see people bending Gravity Forms to their will... if you take advantage of the hooks and the dynamic variables like in this example, you can do so much with it. Most people only scratch the surface of what is possible.

    Posted 14 years ago on Friday January 8, 2010 | Permalink

This topic has been resolved and has been closed to new replies.