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.

Previous URL post into field

  1. I've searched and searched for an answer here and can't seem to find this. So maybe I'm missing something very simple....

    My form needs to have the first field populate with the previous page's title. Here's my exact situation. I am building a website for a client who helps locate missing children and adults. Each person has their own post/page. We need to have a link that says - "I have information about this person." When clicked on the GF will appear with the first field already populated with the Missing Person's name - because the post they just came from has the missing person's name as the post's title.

    I'm thinking this should be a query string, but I am totally unsure what that would be. ANY help is appreciated. THANK YOU

    Posted 12 years ago on Sunday January 29, 2012 | Permalink
  2. jaredcobb
    Member

    I looked into the 'Default Value' functionality in the 'Advanced' tab of an input field, and you're right, there aren't any hooks to be able to inject a url parameter.

    I think you have 2 options (and one is better than the other):

    1) Write an additional hook for yourself in ./common.php 'replace_variables_repopulate()' line 665 where you look for a url parameter of your choice. Not recommended in my opinion because when it's time to upgrade you'll lose that functionality.

    2) Use JavaScript. Here's a snippet that you can put into your page template. (Whichever page template holds your contact form). You could even put this into header.php because it's pretty harmless when a contact form doesn't exist:

    <script>
    jQuery(document).ready(function() {
        var previousName = "<?= urldecode($_GET['previous_name']); ?>";
        jQuery('.gform_wrapper input:eq(0)').val(previousName);
    });
    </script>

    This does 2 things. The first line will look for the url parameter named 'previous_name'. It'll assign a URL decoded (stripped of %20 and things like that) string into a JavaScript variable named 'previousName'. Next it'll look for the gravity form wrapper and its FIRST input field. Once it gets it, it's going to inject the value in 'previousName' into the text field.

    A couple things here... You can modify that jQuery selector if the first text field isn't the proper one to inject into. (I did it that way because you mentioned it was the first field). Otherwise you'll have to assign a custom class to your text field in the Advanced tab of Gravity Forms Edit and then the selector would be something like, "jQuery('.gform_wrapper .my_custom_class_name')".

    On the previous page (which renders the button and url) just make sure you build your URL to include the parameter name 'previous_name' and the value can be the post/page title (which is the missing person's name, it sounds like).

    Have fun!

    Posted 12 years ago on Sunday January 29, 2012 | Permalink
  3. THANK YOU for answering back! This will certainly work!! but one of the problems that I'm running into is that each post is in its own category (4 different ones) -

    http://www.thewebsite.com/missing-children/name/
    http://www.thewebsite.com/missing-adult/name/

    So i don't know how then to put these all in the same category as "previous_name"
    Any way to get around this?

    Posted 12 years ago on Monday January 30, 2012 | Permalink
  4. jaredcobb
    Member

    Hmm, I might have misunderstood the original intent. So, the page that lists the specific missing person (which has a link to the contact form page) can be either an adult or child... But is each post's title simply the person's name (regardless of adult or child category)? If so, then you can build the href to the contact form like so:

    <a href="contactformpage?previous_name=<?php the_title(); ?>">I have information about this person</a>

    Is the category getting into the title so that the title doesn't contain only the name?

    Posted 12 years ago on Monday January 30, 2012 | Permalink