Re: PHP Forms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



R. Van Tassel wrote:
Thanks for the quick response, that seems simple enough, but each row has
about 12 fields, so I just create 12 foreach statements?

Always CC the list..

Number the fields in the same way and you can do something like this:

$number_of_fields = sizeof($_POST['quantity']);
for($i = 1; $i <= $number_of_fields; $i++)
	$name = $_POST['name'][$i];
	$description = $_POST['description'][$i];
	$qty = $_POST['quantity'][$i];
.....
}

and so on.

You'll need to add your own checks to make sure the fields are set correctly..


-----Original Message-----
From: Chris [mailto:dmagick@xxxxxxxxx] Sent: Thursday, May 04, 2006 11:05 PM
To: R. Van Tassel
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  PHP Forms

R. Van Tassel wrote:

I am having an issue with a form, basically an order form, with 10 rows.
Each row is the same, the rows are being generated by a loop and I am
appending the counter of the loop to the name of the form elements (i.e.
quantity1, type1, next row = quantity2, type2, etc)



I can't seem to receive the variables without using sessions, which I'm
trying not to do. If only the first 2 rows are being filled out and
submitted I need to be able to loop through, grab all the variables and
print them out. Can anyone give any suggestion?


Make them an array:

<input type="text" name="quantity[1]" value="X">
<input type="text" name="quantity[2]" value="X">

etc etc.

Then when you post you get an array of quantities which you can loop through:

foreach($_POST['quantity'] as $p => $value) {
   if (empty($value)) continue; // they didn't fill this field in.
   ....
}



--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux