Adding multiple inputs to file php form submit

前端 未结 2 511
抹茶落季
抹茶落季 2021-01-25 09:43

I have a form that looks like so:


         


        
相关标签:
2条回答
  • 2021-01-25 10:14

    If you append [] to your form field names, PHP will take those fields and turn them into an array, e.g.

    <input type="text" name="field[]" value="first" />
    <input type="text" name="field[]" value="second" />
    <input type="text" name="field[]" value="third" />
    

    would produce the following $_POST structure:

    $_POST = array(
        'field' => array(
             0 => 'first',
             1 => 'second',
             2 => 'third',
        )
    );
    

    The alternative is to append incrementing numbers to each field name, as you duplicate the existing field sets for each new block. This provides a nice separation between blocks and allows you guarantee that related fields have the same numerical tag, but it does complicate processing.

    0 讨论(0)
  • 2021-01-25 10:19

    It's not so difficult: main idea is to use IDs for each iteration, so your inputs will have unique names and will be processed without problems

    for ($i=0;$i<10;$i++){
       echo "<input name='removeaccess' type='text' id='it14_{$i}' size='12' maxlength='12' />";
    }
    

    So, you take your code of current set of inputs with lables and add to input names IDs, formed on each circle iteration. Be carefull about ' and "!

    0 讨论(0)
提交回复
热议问题