Title: Question about the code from the example
Last modified: August 22, 2016

---

# Question about the code from the example

 *  [zvonfeng](https://wordpress.org/support/users/zvonfeng/)
 * (@zvonfeng)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/)
 * Hey Mr Simpson,
    I was trying to add multiple content together to the post, and
   I saw you already answered the [question](https://wordpress.org/support/topic/append-text-string-to-post?replies=12).
   However, the example code you gave had a small mistake (I think it is a mistake
   but it might not affect at all.) and i don’t know how to fix it.
 *     ```
       <script type="text/javascript">
           (function($) {
               $(document).ready(function() {
   
                   // CHANGE: list all field id's here
                   $('#field1, #field2, #field3').change(function() {  
   
                     // CHANGE: Format how you want the fields to come out in the post
                      var content =
                            "Answer for Field 1 is: "+ $('#field1').val() + "<br/>" +
                            "Answer for Field 2 is: "+ $('#field2').val() + "<br/>" +
                            "Answer for Field 3 is: "+ $('#field3').val() + "<br/>";
   
                       if ($('#post_content').length > 0) {
                           $('#post_content').val(content);
                       }
                       else {
                           var postContentInput = $("<input>").attr("type", "hidden").attr("name", "post_content").val(answer);
                           $(this).parents('form:first').append($(postContentInput));
                       }
                   });
               })
           })(jQuery);
       </script>
       ```
   
 * So the line after else statement:
    `var postContentInput = $("<input>").attr("
   type", "hidden").attr("name", "post_content").val(answer);` There is no “answer”
   was declared in the variables.(It’s from the last post answer) However, I don’t
   know what I should put in to replace it since I will have more than one filed
   content(field1, field2, field3).
 * Could anyone help to fix the code? I am not very familiar with scrip code.
 * [https://wordpress.org/plugins/form-to-post/](https://wordpress.org/plugins/form-to-post/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [zvonfeng](https://wordpress.org/support/users/zvonfeng/)
 * (@zvonfeng)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727214)
 * Here is my [form](http://pastebin.com/02em43U0), it will send to my email after
   I finished. But it cant generate the post.
    what did I do wrong? =[
 *  Thread Starter [zvonfeng](https://wordpress.org/support/users/zvonfeng/)
 * (@zvonfeng)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727216)
 * hmmm…actually…I copy pasted the demo code from ur previous response, it didn’t
   generate post either =/
 *     ```
       Title [text* post_title] <br/>
       Field1: [text field1 id:field1] <br/>
       Field2: [text field2 id:field2] <br/>
       Field3: [text field3 id:field3] <br/>
       [submit "Post"] <br/>
   
       <script type="text/javascript">
           (function($) {
               $(document).ready(function() {
   
                   // CHANGE: list all field id's here
                   $('#field1, #field2, #field3').change(function() {  
   
                     // CHANGE: Format how you want the fields to come out in the post
                      var content =
                            "Answer for Field 1 is: "+ $('#field1').val() + "<br/>" +
                            "Answer for Field 2 is: "+ $('#field2').val() + "<br/>" +
                            "Answer for Field 3 is: "+ $('#field3').val() + "<br/>";
   
                       if ($('#post_content').length > 0) {
                           $('#post_content').val(content);
                       }
                       else {
                           var postContentInput = $("<input>").attr("type", "hidden").attr("name", "post_content").val(answer);
                           $(this).parents('form:first').append($(postContentInput));
                       }
                   });
               })
           })(jQuery);
       </script>
       ```
   
 *  Thread Starter [zvonfeng](https://wordpress.org/support/users/zvonfeng/)
 * (@zvonfeng)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727217)
 * but this code defiantly worked
 *     ```
       Post Title [text* post_title] <br/>
   
       Post Content (required) <br/>
          [textarea* post_content] <br/>
   
       Categories (required) <br/>
         [checkbox* post_category_name "Uncategorized" "Cat1" "Cat2" "Cat3"] <br/>
   
       [submit "Post"] <br/>
       ```
   
 *  Thread Starter [zvonfeng](https://wordpress.org/support/users/zvonfeng/)
 * (@zvonfeng)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727372)
 * Any help?
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727373)
 * I see in my original post I noted that I had not tested the code. I just wanted
   to give some guidance, not necessarily a working solution. This front-end Contact
   Form 7 manipulation really outside what Form to Post plugin does, so I don’t 
   want to spend hours of my time debugging/supporting it. Sorry.
 * Since this is JQuery/Javascript code, try debugging but putting in alert() calls
   or use the developer debugger tools in your browser.
 *  [Vanessa](https://wordpress.org/support/users/vanessajaded/)
 * (@vanessajaded)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727465)
 * [@zvonfeng](https://wordpress.org/support/users/zvonfeng/) I am in the same boat.
   I need the data of multiple form fields to populate a post. If you find a solution,
   please contact me: [vjbuchan@ncsu.edu](https://wordpress.org/support/topic/question-about-the-code-from-the-example/vjbuchan@ncsu.edu?output_format=md).
   Or if anyone is interested in creating a working solution, I am willing to hire.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Question about the code from the example’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/form-to-post.svg)
 * [Form to Post](https://wordpress.org/plugins/form-to-post/)
 * [Support Threads](https://wordpress.org/support/plugin/form-to-post/)
 * [Active Topics](https://wordpress.org/support/plugin/form-to-post/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/form-to-post/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/form-to-post/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [Vanessa](https://wordpress.org/support/users/vanessajaded/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/question-about-the-code-from-the-example/#post-5727465)
 * Status: not resolved