Adding multiple inputs to file php form submit

前端 未结 2 512
抹茶落季
抹茶落季 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.

    
    
    
    

    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.

提交回复
热议问题