Processing data from multiple multi-line textareas into a multi-dimensional array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I know that this sounds like something overly complex - because it is.
However, if I can keep the user interface the way it is, my users will
be ultra happy! That is the goal...

In general, this is an inventory receiving piece of an overall larger
web-based ERP system.

What I have is a form in which I have a dynamic number of multline
textareas for inputting (possibly barcode scanning in) many serial
numbers per lineitem recieved.

For example:
lineitem01 = widget01; qtyReceived = 2;
lineitem02 = widget02; qtyReceived = 3;
lineitem03 = widget03; qtyReceived = 10;

This would display a form that will generate 3 textarea elements (1
per lineitem received). Inside each textarea element will be input the
serial numbers for each of the widgets received per lineitem. i.e. 2
serial numbers will be entered for widget01; 3 for widget02; and 10
for widget03;

So, what I am trying to do is pass this data over, possibly as a multi-
dimensional array to another form ( or possibly
$_SERVER['PHP_SELF'] )  to update a MySQL database to store the widget/
serial numbers.

Any ideas at all on how to approach this problem are welcomed.


Re: Processing data from multiple multi-line textareas into a multi-dimensional array

Quoted text here. Click to load it

If you display the form like this:

<input type=hidden name=lineitems[] value="widget01">
<textarea name="widget01"></textarea>
<input type=hidden name=lineitems[] value="widget02">
<textarea name="widget02"></textarea>
<input type=hidden name=lineitems[] value="widget03">
<textarea name="widget03"></textarea>

Then when you post the data you can loop through the lineitems array
and get the entry for each textarea by using the value of the lineitem
like so:

foreach ($_POST['lineitems'] as $lineitem) {
    $serial_text = $_POST[$lineitem];
    $serials = explode("\n", $$serial_text);

    // do whatever you need to do with each element serial for this
    // you also would want to trim() each item in the $serials array
before using it in case it has a left over \r in it

Hope this is answering the right question you had.

Site Timeline