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.

question on post forms

  1. I am setting up a form to allow users to submit some information which will be added to a certain post category. i wondered if there was a way to include some of the other fields data into the body field?

    For example i want a website field and i would like to put the website at the end of the body text when the form is submitted so the website address appears at the end of the post.

    Is there a way to achieve this?

    Posted 15 years ago on Tuesday September 29, 2009 | Permalink
  2. Currently there is no way to do this, although it could be achieved programmatically using the hooks and manipulating the data before it is saved.

    We plan on introducing the ability to format the post body content and insert post image, other field values, etc. in the 1.3 release of the plugin.

    Posted 15 years ago on Tuesday September 29, 2009 | Permalink
  3. hi Carl now that 1.3 has been released is this now possible?

    Posted 14 years ago on Friday November 20, 2009 | Permalink
  4. Unfortunately that feature did not make it into 1.3.
    It should be pretty straight forward to do what you need using a few lines of PHP. Place the following code snippet in you template's functions.php file.

    add_filter("gform_post_data", "append_url_to_content", 10, 2);
    function append_url_to_content($post_data, $form){
       //Replace XXX with the website input name. View the HTML source to find it.
        $post_data["post_content"] .= "<br/>" . $_POST["input_XXX"];
        return $post_data;
    }
    Posted 14 years ago on Friday November 20, 2009 | Permalink
  5. thanks for the quick response i will give that a go. would it also be easy to modify the code to allow me to append another field with a single word?

    let me explain what i am trying to achieve.
    I want to create a form for a client to submit a testimonial they enter their name/company name and i want gf to append "Testimonal" to the end of their name. This is the title for a post.

    then they type in their web address.
    finally they fill out a paragraph for the testimonial. which will be the post content.

    when submitted i want the name (post title) to read as Name Testimonial and the testimonial text(post content) to have their name and website appended to the end of the text.

    is there somewhere on here with some information about the hooks you have used?

    Posted 14 years ago on Friday November 20, 2009 | Permalink
  6. The following should be what you need.

    add_filter("gform_post_data", "append_url_to_content", 10, 2);
    function append_url_to_content($post_data, $form){
        $post_data["post_content"] .= "<br/><br/>" . $_POST["NAME_INPUT_ID"] . "<br/>" . $_POST["WEBSITE_INPUT_ID"];
    
        $post_data["post_title"] .= " Testimonial";
        return $post_data;
    }

    You just have to replace NAME_INPUT_ID and WEBSITE_INPUT_ID with your actual input names. (i.e $_POST["input_5"];). You can find the input id by inspecting the HTML and looking at the name="xxx" of the field.

    Let me know how it goes.

    Posted 14 years ago on Friday November 20, 2009 | Permalink
  7. thanks alex it worked perfectly :)

    Posted 14 years ago on Friday November 20, 2009 | Permalink
  8. just one question, will this happen for all the forms on the site? i have a contact form as well

    Posted 14 years ago on Saturday November 21, 2009 | Permalink
  9. It will happen for all forms that have post fields in them. We can limit for a specific form, but if your Contact Us form does not have any post fields, it won't affect it.

    Posted 14 years ago on Saturday November 21, 2009 | Permalink
  10. RichardBest
    Member

    Hi Alex

    I think, but am not quite sure, that this thread is getting pretty close to a GF-related need I have. Would really appreciate any comments you might have please. Let me explain.

    I'm using GF in conjunction with the Single Post Template plugin. Through the custom field trick you showed me, I'm using a specific post template for each form, and each form contains a significant number of post custom fields. I'm using this set-up in such a way that the outputted post is crafted entirely from the custom field inputs. There is no "post body" in the normal sense. The body is completely blank. How this works is that if, for example, someone selects "Yes" into a custom field question in the form, php code in the single post template file will output "this paragraph of text". Alternatively, if that person selects "No", then the php code will output an alternative paragraph of text. And so on, repeated many times for many different custom fields. All the paragraph text sits in the single post template file and is called, as appropriate, by conditional calls to the custom field data.

    The "issue" this creates is that when I try to use plugins like "WP-Print" or "Save as Text and HTML", my post content cannot be seen, because those plugins are looking for the "post body" (which in my case is blank). The same applies to the posts when they are listed on the home page and the RSS/Atom feeds, again because the content is not in the body but created on the fly by the 'custom field call code' in the single post template.

    So what I'm wondering is whether it's possible to add a function to the functions.php file, for example, to enable the content residing in the single post template to be treated as if it were body text, so that it displays when using the plugins I've mentioned and so that it displays on the homepage and in the feeds.

    I hope this makes sense. If you've time, I'd really appreciate your assistance with this.

    Many thanks in advance for any help you might be able to provide.

    Richard

    Posted 14 years ago on Wednesday November 25, 2009 | Permalink
  11. Richard,
    I think what you need to do is actually populate the post body instead of leaving it blank. You can do that using the gform_post_data hook and apply the same conditions you are applying on the single post data.

    Posted 14 years ago on Thursday November 26, 2009 | Permalink
  12. RichardBest
    Member

    Thanks Alex. Much appreciated.

    Sorry if this is an ignorant question, but does that entail adding something to the functions.php file?

    Posted 14 years ago on Thursday November 26, 2009 | Permalink
  13. Hello Richard, yes to take advantage of the hooks to interact with Gravity Forms using PHP you will want to place the code in your themes functions.php file.

    Posted 14 years ago on Thursday November 26, 2009 | Permalink
  14. RichardBest
    Member

    Thanks Carl.

    I've had a try at understanding how to add the right code to the functions.php but, to be honest, am a little out of my depth.

    Is there any chance one of you guys could steer me in the right direction please? Would much appreciate it (and happy to make a paypal donation if we can get this working as explained above).

    Many thanks
    Richard

    Posted 14 years ago on Thursday November 26, 2009 | Permalink
  15. Richard,
    Send me an email with your FTP information and I will be happy to place the code in the right spot for you.

    Posted 14 years ago on Thursday November 26, 2009 | Permalink
  16. RichardBest
    Member

    Thanks Alex. Much appreciated. I've no problem placing the code in the right place if you tell me where it goes (I understand in the theme's functions.php file between the php tags) ; my problem is more knowing what the inserted code should be in the first place and where/how I insert the custom-field-calling code that I currently have in my single post template file, bearing in mind that it's replete with HTML as well. You can email me at richard dot best at insideoutlegal.co.nz if that helps.

    I really appreciate your help with this. Thanks.

    Richard

    Posted 14 years ago on Thursday November 26, 2009 | Permalink