1

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, type, color, unit price, qty. I have place <input> and <select> tags inside <td> tags to collect data.

I need to submit a complete invoice to a database. The problem I'm having is I'm not sure how to get input values to my $_POST variables since the number of <input> and <select> vary from time to time based on the items on the invoice.

I can give dynamic or static names to input fields based on the table row id when they are generated using javascript. But how can I collect these data in the submit end to my php arrays or variables?

This is one table row. All other are similar to this.

<tr class="table_row_blue">
                <td class="table_data_index">1</td>
                <td><select>
                    <option>Test</option>
                    </select></td>
                <td class="table_data_item"><select>   
                    <option>&nbsp;2GB&nbsp;</option>
                </select></td>
                <td><input type="text" id="price_field" size="6"></td> 
                <td><input type="text" id="qty_field" size="6"></td> 
                <td><span class="table_subtotal">125,200.00</span></td>

            </tr>

Please give me some ideas to implement my idea.

3
  • in php part use the if isset($_POST['optional property']) to check for values to see if they are present Commented Jun 18, 2011 at 7:14
  • @lbu ya but this table might have 300 total inputs then should I have to check this dynamically or is there a way to do this dynamically.I mean using a loop or something like that. Commented Jun 18, 2011 at 7:18
  • I think you should edit your question. Some things are not clear: what do you mean get values to $_POST? it is browser what places input values to post on submit. Second your input fields don't have a name. Third in second paragraphs second sentence seems to have excess words, that makes it a bit unclear. And lastly do you know that you can have array coming from forms? If you just hive names yo your fields i.e.: "items[]" and then if you have some some inputs with such name all of them will end up in $_POST['items'] and that will be an array with all values from fields named "items[]" Commented Jun 18, 2011 at 7:19

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

You can have input fields which submit to an array:

<input type="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)

1 Comment

I would not put the counter before ['price_field']. I would use price_field[]. This way you don't need to maintain any counters. The submission data will all be sensibly grouped by shared indices. Transposing the data is much simpler than maintaining counters on the client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.