1

I have jquery code that appends a field into a form. When I submit that form, the fields that get appended are not available to PHP. Is there anything special I have to do to pick these fields up? Here is the code:

$(document).ready(function() {
   window.unique = 0;

    //hides alert
    $("hide").click(function(){
     $("#alert").hide();
    });


     $(document).on('click', '#toggle_header', function(){
         window.unique++
            $("#header_list").append("<li><input type='text' name='header_name" + unique  + "' placeholder='name'><input type='text' name='header_value" + unique  + "' placeholder='value'><a href='#' id='toggle_header_remove'><i class='icon-remove'></i></a></li>");
     });







     $(document).on('click', '#submit_query', function() {
        $.ajax({
            url: 'index.php',
            type: 'post',
            data: $(this).serialize(),
            cache: false,
            dataType: 'json',
            success: function(data) {
            }
            })
    })




});



<form method='post' action='index.php' id='main'>
                <input class="span5" id="appendedInputButtons" type="text" name='url'>
                <button class='btn btn-inverse' id='submit_query'>GET</button>

            </div>
            </br><a href='#' id='toggle_header'>add header<i class='icon-plus'></i></a>
            </br>
            <ol id='header_list'>
            </ol>
</form>

A dump of the POST variable in php will show all values input in the form except the ones that were added with jquery.

2
  • You probably don't want to use $(this).serialize() for the data element. It's more likely to be $('#your_form_id').serialize(). I don't see anything in your code that adds values to the input form, so I'm not sure what you mean by php will show all values input in the form except... Commented Mar 12, 2013 at 23:30
  • Did you try adding enctype='multipart/form-data' to the <form> tag? Have you tried setting a variable value to $(this).serializeArray() and then loop through to check if the file input was included? Commented Jun 29, 2016 at 20:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.