Click to See Complete Forum and Search --> : Populating an array with form values


mattastic
03-02-2007, 08:22 AM
Hi Folks,

I'm really stuck with this.

I need to set form variables to an array so I can loop through them to contruct my queries.

I have no PHP code at the moment as I dont know where to start.

Basically the form is quite complicated, Its a booking form for equipment.

There are time slots, main items to be booked with these time slots, and additional items for the main items. There may or may not be additional items for each main item. However I can check to see if there defined ok. Thats not my problem,

So I guess I need a 3d array?

Here are the fields to be stored. I can output them fine on my action page, but its storing them that the problem.

ITEM1_1 - Lap
SUBITEM1_1_1 - Proj
SUBITEM1_1_2 - SPK
SUBITEM1_1_TOTAL - 4 (total number of additional items available for that item)
ITEM1_2 - DVD
SUBITEM1_2_2 - SPK
SUBITEM1_2_TOTAL - 3 (total number of additional items available for that item)

ITEM2_1 - CD
ITEM2_2 - Lap
SUBITEM2_2_3 - SCR
SUBITEM2_2_TOTAL - 4 (total number of additional items available for that item)


Can anyone help?

Thankyou

Sid3335
03-02-2007, 08:48 AM
not sure if i get what you mean entirely, but if you construct your html correctly the values of your form will be stored as you wish in the $_POST array.

for example:

<?php

echo "<pre>" ;
print_r($_POST) ;
echo "</pre>" ;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<form id="form1" name="form1" method="post" action="">
<p>
<input type="text" name="item1[name]" />
</p>
<p>
<input type="text" name="item1[price]" />
</p>
<p>
<input type="text" name="item2[name]" />
</p>
<p>
<input type="text" name="item2[price]" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>

</body>
</html>


hope this helps, let me know if its not what you wanted

Sid3335
03-02-2007, 08:51 AM
output from above post:


Array
(
[item1] => Array
(
[name] => name1
[price] => price1
)

[item2] => Array
(
[name] => name2
[price] => price2
)

)


forgot, don't name your submit button if you don't want it posted

mattastic
03-02-2007, 09:34 AM
Thanks for your reply.
Works great