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.

Using the form to enable users to submit content

  1. nicole
    Member

    I would like to enable users to submit recipes. I would like to have a form that they fill out with the following fields:
    ingredients
    method
    photo of the result
    All 3 fields are required.
    In the output (post) I would like the title to appear as well as the content:
    ingredients: blah blah
    method: blah blah

    When I tried I do not get the word ingredients but only the info that was entered.

    Is there a way to publish a form so that it looks like a post (i.e. has the question and answer etc)?

    I have looked everywhere to find a way to do this and have played around with the form with no success.

    Posted 13 years ago on Friday July 15, 2011 | Permalink
  2. No problem to do this with Gravity Forms. Here is an example form:
    http://guitar.chrishajer.com/submit-a-recipe/

    Here are two example recipes I submitted:
    http://guitar.chrishajer.com/category/recipes/

    You just need a some text to your content template for the post body. Here is the content template I used for the post body to achieve this:

    {Photo of the result:4:medium:left}
    <p><strong>Ingredients:</strong></p>
    <p>{Ingredients:3}</p><br style="clear:both;" />
    <strong>How to make it</strong>
    <p>{Method:5}</p>

    That takes the submitted photo, uses the medium size and floats it left (top left corner of the post.)

    Then creates a paragraph and uses what was submitted as "ingredients" there.

    Finally, I use the "method" in another paragraph.

    The text you would need to add to appear with the submitted information is "How to make it" (you wanted "method") and "Ingredients:". The magic is all in the content template. Play around with your form and have fun with your submissions.

    Posted 13 years ago on Friday July 15, 2011 | Permalink
  3. nicole
    Member

    Thanks!
    Which field did you use for each? When I use the body more than once it only uses one. I don't understand how to make a seperate field for method and another for ingredients.

    Posted 13 years ago on Friday July 15, 2011 | Permalink
  4. You can have only one post body field. In my form, the "Method" is the post body. The other required post field is the Title. And I used a third post field for the image.

    But the ingredients field is not a post field at all. It's just paragraph text (a normal field). Save the form after adding all your fields, then go back to the post body field (method) and check "Use content template". Then, there will be a drop down with ALL your form fields available to insert into the post body. Anything that is submitted with the form is available for you to put in the post body.

    So, there are a few fields inserted from the drop down into the content template ({Photo of the result:4:medium:left}, {Ingredients:3}, {Method:5}). Then, in the content template, you add whatever words or formatting you want to surround the submitted content. In my case, I added some paragraph tags, and <strong>Ingredients:</strong> and `<strong>How to make it</strong>
    `

    The content template is a combination of content submitted with the form, and the additional text and markup you want to be present on every post created by a submission.

    Posted 13 years ago on Friday July 15, 2011 | Permalink
  5. nicole
    Member

    Thank you very much. That was very helpful. If someone leaves a field blank then I would like the title of that field not to appear on the post. How do I do that?

    Posted 13 years ago on Saturday July 16, 2011 | Permalink
  6. I thought all your fields were required though?

    I don't know if there's a way in the content template to say If no ingredients are submitted, don't show the "Ingredients" heading. Is that what you're trying to do? To prevent the problem of a section of the post being blank (just a title, no content)?

    You could probably do it differently by using custom fields and then modifying your post template (or creating a post template for recipes specifically) but it's more complicated than what we've accomplished here. It can be done though.

    Posted 13 years ago on Saturday July 16, 2011 | Permalink
  7. nicole
    Member

    I have expanded the form to include additional optional fields too that will not always be included and are not required. Is there anywhere I can read up on how to accomplish this?

    Posted 13 years ago on Sunday July 17, 2011 | Permalink
  8. ycb
    Member

    @ Chris:

    I have a site with user submitted content as well and am using the content template successfully. The issue I am having is in formatting the content -- when people enter blocks of text, the line breaks disappear and the output is a large block of text. Since the content is one form field, I can't add the required formatting in the content template.

    Ex: someone submits

    paragraph 1

    paragraph 2

    paragraph 3

    The result is:

    paragraph 1 paragraph 2 paragraph 3

    And I can't fix this b/c all I can do with the content template is:

    <p>[content]</p>

    which gets me:

    <p>paragraph 1 paragraph 2 paragraph 3</p>

    There is a WordPress filter called autop to convert line breaks to br and p tags. How can we run this filter on the contents of the form?

    Posted 13 years ago on Friday July 29, 2011 | Permalink
  9. @ycb, something is going on with your form. The default is to add tags where line breaks are in the form submission.

    I posted 5 paragraphs of plain text to this form and you can see the result here. The blank lines were converted to markup just fine. View the source.

    Please feel free to submit a test and see how it works.

    Posted 13 years ago on Friday July 29, 2011 | Permalink
  10. ycb
    Member

    @Chris

    Thanks for your prompt and thorough response. I tried your form -- and got the correct result. But we're still having problems. To output, I'm using a function to grab the first image, then the_content, then the custom field (in single.php):

    <img class="alignright" src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" />
    
    <?php the_content(); ?>
    
    	<?php $url = get_post_meta($post->ID, 'submit_url', true); ?>
    
    <p><b>Read the Original Article:  <a href="<?php echo $url; ?>"><?php echo $url; ?></a></b></p>

    Please see the results of a user submitted form here: http://soulinthemachine.com/2011/07/planetary-nebula/

    compared to the correct output here: http://gravity.chrishajer.com/category/stories/

    ( copy/pasted from here http://www.myfoxhouston.com/dpps/dpg_original/new-planetary-nebula-found-by-amateur-astronomer-dpgoh-20110728-ch_14326206 )

    Any idea why our line breaks don't convert to markup?

    Posted 13 years ago on Saturday July 30, 2011 | Permalink
  11. @ycb, I think it has to do with the source of the text you're pasting in. I've seen this before, commonly with WikiPedia articles. Nothing particular about them, I've just seen it there.

    If you copy and paste from that Fox News page into something like notepad (or any plain text editor) you might see that there is just a new line at the end of each paragraph, not a new line and a blank line. In the plain text I used, There was a new line and then a blank line. Gravity Forms added a < br > for the new line and a < br > for the blank line. That's why it looked like paragraphs on my site.

    I did two tests using my form and your Fox News content:

    Good
    Bad

    The only difference was that I added a blank line after each carriage return (or end of line) in the Fox News content. What Gravity Forms does to the content that is submitted is dependent on how the content is formatted. When there are no blank lines in the pasted source, it won't look like paragraphs with space between them on your site.

    So, knowing that, I think it gets us back to your original question :-)

    Posted 13 years ago on Saturday July 30, 2011 | Permalink
  12. To answer the original question, you would apply the wpautop function using the gform_post_data hook, documented here:

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

    However, my understanding of the wpautop function makes me think it would not help in this case. If the text you pasted in DID have blank lines between carriage returns, then it would convert those to paragraphs rather than two br tags the way it's done now. That might be more correct semantically, but it doesn't solve your problem. The input text from the Fox News article just has a new line at the end of each paragraph, not a blank line in between paragraphs, at least when I pasted it into a text editor.

    A lot of this is going to depend on where it's being copied and pasted from.

    Posted 13 years ago on Saturday July 30, 2011 | Permalink
  13. ycb
    Member

    @Chris, thanks again! It sounds like the auto formatting will correctly be applied in many/most cases, and if I want to apply the autop filter to the gform_post_data hook I can (but it most likely won't fix the problem). So we'll just have to manually insert line breaks in the case that the source text does not have formatting that results in the correct output. Have a great day!

    Posted 13 years ago on Tuesday August 2, 2011 | Permalink
  14. Thank you for the update. Good luck.

    Posted 13 years ago on Tuesday August 2, 2011 | Permalink

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