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.

Populate Dynamically

  1. Aejandro
    Member

    Hello:

    My website has around 50 products and I want to use the same form for users enquire about them.

    The problem is how to know what product is the user enquiring about.

    So I need a single line text field be populated with the title of the "product" (custom post type).

    I was searching around and found this post: http://www.gravityhelp.com/forums/topic/dynamically-populate-based-on-post-name

    But I am still not getting the single text field dinamically populated.

    Is anything I am missing? Anything I should double check?

    Thank you

    Posted 11 years ago on Wednesday February 6, 2013 | Permalink
  2. David Peralty

    What code are you using exactly and can you link to your form?

    Posted 11 years ago on Thursday February 7, 2013 | Permalink
  3. Aejandro
    Member

    Hello, I am using this code:

    add_filter("gform_pre_render", "populate_post_name");
    function populate_post_name($form){
    	global $post;
    	    if($form["id"] != 1) // Change [2] to the ID of the form you want to use
    	       return $form;
    		$post_name = get_the_title($post->ID);
    		$form["fields"][29]["defaultValue"] = $post_name ; //Change [3] to the nth (-1) field you want to populate.
    		return $form;
    
    }

    The link: http://goo.gl/m68vW

    Thanks

    Posted 11 years ago on Thursday February 7, 2013 | Permalink
  4. @Aejandro, if you are embedding the same form in every page, then you can set the default value of the field using this merge tag:

    {embed_post:post_title}

    If you are linking to the same one form from multiple pages, and want the page title that the visitor came from, let us know that. From your code, looks like you just want the post title for the current post, so the merge tag above should take care of that.

    Posted 11 years ago on Thursday February 7, 2013 | Permalink
  5. Aejandro
    Member

    I can not believe it was so obvious using merge tags.

    Also, I need to implement the other way: "linking to the same one form from multiple pages, and want the page title that the visitor came from". How can it be achieved?

    Thank you,

    Posted 11 years ago on Thursday February 7, 2013 | Permalink
  6. In your page where the form is embedded, I assume you are using the shortcode to embed the form? If that's the case, you can modify the shortcode to send field values to the form. You can send the page title in the shortcode. There will need to be a field in the form to hold the page title, and it needs to be checked "Allow field to be populated dynamically." Give it a parameter name like "pagetitle" or something. Then, in the shortcode you can do this:

    [gravityform id="3" name="Form 3 Name" title="false" ajax="false" field_values='pagetitle=This Page Title']

    Will that work for you?

    Posted 11 years ago on Friday February 8, 2013 | Permalink
  7. Aejandro
    Member

    Nope, it does not work for me.

    The goal is not to get the page title where the form is embedded.

    The goal is to get the page title where the visitor came from.

    I followed your instructions and here you have the link: http://goo.gl/lt6hj

    Thank you for your help.

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  8. I think I have it now. I described a different way of getting the existing page title in the form entry. You did not need that.

    In the page which sends a visitor to your form (I assume there are multiple pages all pointing to the same form?) you must have a link to the page where the form is embedded, correct? If that is the case, then you can add query string parameters to that link. The parameter will be "pagetitle" and you will just add it to the URL of the page where your form is embedded.

    So, if your existing URL was this:

    <a href="http://example.com/place-an-order/" rel="nofollow">Place your order now</a>

    You would modify it to look like this and send the page title to the page with your form embedded:

    <a href="http://example.com/place-an-order/?pagetitle=Page Title of Page I was On" rel="nofollow">Place your order now</a>

    That will capture "Page Title of Page I was On" in the field with the parameter name "pagetitle" which you checked so that it can "Allow field to be populated dynamically".

    Ignore the rel="nofollow" stuff. That is added by the forum software

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  9. Aejandro
    Member

    You rock!!!

    It works like a charm.

    Thank you very much!!

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  10. Glad that solution will work for you.

    Posted 11 years ago on Saturday February 9, 2013 | Permalink

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