Skip to content Skip to sidebar Skip to footer

Adding Multiple Inputs To File Php Form Submit

I have a form that looks like so:

Solution 1:

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.


Solution 2:

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 "!


Post a Comment for "Adding Multiple Inputs To File Php Form Submit"