PDA

View Full Version : Help needed... FORMS & PHP (not as noob as you think)


Deaths
03-28-2005, 10:09 AM
Ok, here's my problem:

I'm currently using an XHTML form (duh), which sends some data to a PHP file.

Now, one of the text input boxes, looks like this:

<input name="products[$order[productid]][quantity]" type="text" class="bginput" value="1" size="2">

Lets say $order[productid] is 1, so the name will be this:
products[1][quantity]

Now, I was wondering how I can let PHP read that "1" (not static, but dynamic I mean. If it would be 2, it would read "2", if it would be "3" it would read "3".
I'm pretty sure this is possible, but I can't figure it out.

Help is appreciated, as always.

pie
03-28-2005, 11:28 AM
I'd parse the $variable OUT of html personally.

Deaths
03-28-2005, 11:56 AM
Yes, but doing it like this is a lot more effective (you would need to see the code to understand this, though)

Marco van Herwaarden
03-28-2005, 09:03 PM
Try:foreach ($products AS $orderid=>$quantity)
{
foreach ($quantity AS $key=>$value)
{
....
}
}

Deaths
03-29-2005, 06:28 AM
I don't get how I could get that "1" from products[1][quantity] with your code...

I've tried str_replace, but I would need to know the number already...

If it is possible with your code, could you maybe give an example?

Marco van Herwaarden
03-29-2005, 06:34 AM
$products will hodl the '1'.

I already gave you an example.

Deaths
03-29-2005, 06:46 AM
I believe you when you say it'll hold a 1, trust me ^^.

But the question is, how should I define products[1][quantity] with that code?
Should I globalize it, or just use the $_POST['products[1][quantity]']?

Marco van Herwaarden
03-29-2005, 08:11 AM
You should globalize it, but using the $_POST would also work.

Deaths
03-29-2005, 09:08 AM
Could you maybe give an example?
What I'm doing is this:

globalize($_POST, array('products[1][quantity]'));
foreach ($products AS $orderid=>$quantity)
{
foreach ($quantity AS $key=>$value)
{
echo "$products";
}
}

It then errors me out:
Warning: Invalid argument supplied for foreach() in /products.php on line 70

This is on line 70:

foreach ($products AS $orderid=>$quantity)

Marco van Herwaarden
03-29-2005, 10:57 AM
globalize($_POST, array('products'));