Skip to content Skip to sidebar Skip to footer

Variable Number Of Input Fields In Form

I have a HTML table base invoice for collecting the details of a order. New table rows can be added or deleted to this as the user needs them. Table has columns like item name, typ

Solution 1:

encapsulate all the varying parts in separate tables in the database. so you can store them separately and relate to each other with foreign keys.

also it's a good idea to use array naming for you HTML inputs like

<input name="data[Invoice][field1]" />
<input name="data[Invoice][field2]" />

this gives you data, which is more structured and easy to iterate.

Solution 2:

Add a hidden form value, which will hold the number of rows you are going to submit. On the PHP end, first of all check the number of rows and then get all values using a row index.

Solution 3:

You can have input fields which submit to an array:

<inputtype="text"id="price_field" name="data[0][price_field]" size="6">

which will appear in you $_POST as

$_POST['data'][0]['price_field']

I would suggest you use the unique id of an entry as differentiator (replacing the 0 in the above example)

Post a Comment for "Variable Number Of Input Fields In Form"