View Full Version : Submiting multiple forms with one Submit button

10-01-2008, 04:58 PM
Hi to all

I'm php novice,and tried to solve this problem for 3 days but no success. I've tried other php-help forums, Google, but cannot find an appropriate solution for the problem i'm stuck in.
I'm trying to make a simple script in which the user first enters the hotel info and then the room number that the hotel has.

After entering the the room number, the next step is to enter a info about each room separately (beds, floor,etc).
In this step i have manged to display enough forms that equals to the room number entered in the previous step (e.g if the hotel has 10 rooms, then the same form is displayed 10 times).

Also i have managed to increment the form fields respectively (e.g. the first form has room_name1 as a name for the field, the second has room_name2, and so on).

I want to process all values of each form as a separate record in the database, and for that to use only one submit button.
For example, if the hotel has 10 rooms, then the same form is displayed 10 times, and only one submit button for all the forms, which will process all 10 forms,each one as a separate record.
I tried several variations of the "for" loop, but i only "succeed" to insert the last form data, and not all the previous.

Does anyone have an idea how to make a "for" loop for quering (inserting) values from several forms that have dynamic form names?

Thanks in advance.

10-02-2008, 05:41 AM
There's no need to complicate things with multiple forms.

Presumably, your form fields are nice and semantically enclosed within <fieldset></fieldset> tags, you simply instantiate enough copies of the fieldset to accomodate the number of rooms. Then you have 1 form and 1 submit button - quick and painless.

12-12-2008, 01:17 AM
This seems like a reasonable solution, but I am having trouble making it work.
<form action="somejava" method="POST">
(this next part multiple times)
<input type="hidden" name="name" value="whatever"/>
<input type="radio" name="category" value="val1"/>
<input type="radio" name="category" value="val2"/>
<input type="radio" name="category" value="val3"/>
(then a submit to submit all info)
<input type="submit" value="submit"/>
Should I be able to click one radio button from each fieldset?
I would need to access the values from a java HttpServletRequest object if that changes anything.