• Hey, I was trying to add multiple content together to the post, and I saw the author already answered the question. However, the example code he gave has 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/support/plugin/form-to-post

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

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