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.

Link form responses to particular (custom) posts

  1. anu.gupta
    Member

    What's the best way of linking a form response with the (custom) post that the custom post that the form appeared on?

    I have a custom post type called questions. I want to have a form that is used to submit answers and have the answers be associated with the post. I need to leave comments as they are, which means I can't use comments for this purpose.

    I'm assuming I'll need to add the post id to the form, but would appreciate some help in working out how to do that, and also then the filter the responses by post_id

    Posted 13 years ago on Monday February 7, 2011 | Permalink
  2. So you want to have Posts that are associated with another Post? You can do this but you would have to store the Post ID as post meta on the new Posts that are created... which would associate the new Post with the Post they were submitted from.

    You would then have to write a custom loop to pull in and display posts with that post id stored in custom meta. It is doable but obviously will require customizations to your theme to display these associated posts.

    - Add a Post Custom Field to your form

    - Edit the Post Custom Field and give it a Field Label (ex. Associated Post)

    - For Custom Field Name Select NEW and give it a Custom Field Name (ex. associated_post_id). The custom field name is the meta key, so no spaces.

    - Select the Advanced Tab

    - In the Default Value select "Embed Post/Page ID" which will insert this into the Default Value: {embed_post:ID}

    - Set the Visibility to "Admin Only"

    This should now create a field that will store the post ID of the post the form was submitted from as post meta with the key you configured in the custom field name. You can then write a WordPress loop to display all posts with that custom field key that have a value equal to the post id for the post that is being displayed.

    Posted 13 years ago on Monday February 7, 2011 | Permalink
  3. Hi Carl, I know this thread is close to giving me the answer I need, but have to ask if that's a correct assumption before I lose hours working it out!

    I have set up a form, and am using the results to create posts, I then wish to have a 2nd response form at the foot of each post - that
    a) sends me results I can link back to the post ID / title
    b) also sends the results to an email address that was entered into the original form

    Can this work?

    Secondly, I've inserted form code into the loop (I added the shortcode into a post, then copied what appears to be the relevant code from the source) but my form is not properly formatted - I've set the form to output css - do I need to insert some css code into my header / footer?

    thanks in advance
    J

    http://www.shootingholidays.co.uk/woodpigeon-shooting/woodpigeon-in-surrey/

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  4. You can't copy-n-paste the form source code. It won't work. The form has to be output by the shortcode or function call. You can't just copy-n-paste the form HTML itself. So if that is what you are doing, that is why it's not formatting correctly. So you have to use the shortcode, or the function call. If you use the function call, you may have to manually enqueue the necessary scripts. The shortcode should do this automatically if executed within a loop.

    To answer your questions above, yes these should be possible if you set it up correctly.

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  5. Hi Carl,

    OK, I've tried pasting the shortcode into the loop, both as it is and as:
    <?php if (is_single() ) { ?>
    [gravityform id=2 name=Information Response]
    <?php }; ?>

    but either way just it displays the shortcode instead of the form...
    see: http://www.shootingholidays.co.uk/woodpigeon-shooting/woodpigeon-in-surrey/

    With 'function call' - that's waaaay beyond my experience! Can you point me towards a tutorial?

    thanks
    J

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  6. Shortcode's are only executed when they are used in the post body content. They aren't parsed if you place them directly in your PHP template files. They are only parsed if they are in the Post Content themselves. So that is why it isn't being parsed. That shortcode needs to go in the content of the post that is being displayed.

    If you want to display a form via PHP in your theme template files you have to use the function call.

    Documentation for both can be found here:

    http://www.gravityhelp.com/documentation/page/Embedding_A_Form

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  7. Wow - I did it!
    Thanks for that - used the function call, and worked out where to paste the enqueue script - the form is perfectly formatted now.

    so my other issue which I guess is far more complex:
    a) sends me results I can trace back to the originating post ID / title
    and if its in any possible:
    b) also sends the results to an email address that was entered into the original form

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  8. @macnet You need to configure the Notifications for that form. A and B are both possible with the tools available when configuring your Notifications.

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink