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 Add Post ID to Query string

  1. theslink2000
    Member

    Hi,

    I've been trying to accomplish something I thought would be very simple but for some reason I have just a brick wall.

    Basically I have a form that when it loads needs to have a hidden field dynamically populated. The form is loaded from a hyperlink on a post page so I want to pass the post ID to the form via the Query String. I have been through all your documentation and every forum post I can find, including those posted by your admins pointing to a discussion that apparently answers this sort of question, but I just can't get anywhere!

    I can easily pass text dynamically into the field via the query string but I can't get the post id to dynamically render. The merge tags don't work (I'm assuming because they only function on submitting a form) and php code doesn't seem to work.

    Please PLEASE can someone help me with this!

    Many thanks.

    Posted 10 years ago on Wednesday August 8, 2012 | Permalink
  2. David Peralty

    Can you link to your form and walk me through more of what you are trying to do? Seems like you have a value being passed by a query string that is working, but are unable to get the post id of some sort?

    Posted 10 years ago on Wednesday August 8, 2012 | Permalink
  3. theslink2000
    Member

    Hi David,

    Yeah you're spot on I have a post page on screen called Test with an id of 215 but for the life of me I can't figure out how to tell the query string of the link to send it.

    Unfortunately this is only running on a local install so I can't show you but here's the link code (I've removed the opening and closing <> to make it visable:

    a href="http://localhost/wordpress/my-settings/add-doctor?bar=no&gp_surgery=$post_id" rel="nofollow">Add Doctor</a

    Obviously the url links to the form (yes it loads in an iframe, but that doesn't effect anything). The next bit "?bar=no" simply prevents the wordpress admin bar from loading.

    The last bit "&gp_surgery=" is as much as I've figured out from your documentation. This is my dynamic population parameter. If I add anything after it it will print it exactly in the field when the iframe loads and I need it to dynamically take the post id from the page it's coming from (the template is used on every instance of this post type), as you can see I've currently got "$post_id" in there as a place holder.

    The needs to be correct as the field data is taken at gform_pre_submission to write a post type relationship so I need to this be dynamic.

    Hope that explains things well enough for you to understand bud.

    Cheers in advance.

    Posted 10 years ago on Wednesday August 8, 2012 | Permalink
  4. theslink2000
    Member

    Ok I've slept on it for a bit and I've taken a massive step forwards and have this working! The problem I had was that I was trying to resolve php and other code snippets in a hyperlink, now I don't know if this is even possible but I realised that taking a step backwards was the way to go so I've manually created a shortcode to fix this issue like so http://pastie.org/4448582.

    This works beautifully for in conjunction with the iframe and the rest of my code (it's handling custom post type relationships with wp-views / wp-types).

    The only thing left for me to figure out was how to submit the same function on submission of the form so the page reloads exactly as it does the first time, as the shortcode doesn't work, unless I'm doing something wrong.

    This was solved by keeping the url in the form confirmation redirect up until ?bar=no& then adding the following merge code -

    gp_surgery={Parent ID (Surgery):7}

    One thing to point out that I didn't understand until I tested it and that I've not seen obviously stated in the documentation is the structure of this. The first bit is simple, this is the function name of the field to dynamically populate, then the field name and the number is the field ID.

    Sorted all this and boom, working as planned!

    P.S. - Is it possible in a future update for form conformation redirect to accept shortcodes please?

    Posted 10 years ago on Friday August 10, 2012 | Permalink