不要从字段数组POST获得输入

I've downloaded a dynamic input field script from google,

but now I want to get the values from it.

This is the script;

<script type="text/javascript">
    $(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext['+x+']"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});
    </script>

HTML

<form action="addquestiontosection2.php" method="post">

<div class="input_fields_wrap">
            <button class="add_field_button">Add more values</button>
            <div><input type="text" name="mytext[1]"></input></div>
        </div>
</form>

PHP

$item1 = $_POST['mytext']['1'];

$item2= $_POST['mytext']['2'];

Item1 and Item2 returns empty.

Thank you very much.

Is that all your html? If that is a form, you should put that inside a form instead of relying on the button.

<div class="input_fields_wrap">
    <form method="post" action="somephpfile.php">
       <button class="add_field_button">Add more values</button>
       <div><input type="text" name="mytext[1]"></input></div>
    </form>
</div>

You need to use a form to post the data;

<div class="input_fields_wrap">
  <form method="POST" action='#'>
     <button class="add_field_button">Add more values</button>
     <div><input type="text" name="mytext[1]"></input></div>
  </form>
</div>

By using '#' as the action the form will post the data to the same page, so you must use $item1 = $_POST['mytext']['1']; on this page also. if you wish to post it to an external php file you can change the 'action' destination.