You can have multiple submit buttons on a form, just give them all the same name. If a submit button has no name, it's not passed to the action script. One caveat: On many visual browsers, the button has to actually be clicked with the mouse; you can't just click the "return" key or neither submit button is passed.
Two Submit Buttons on Form?
/me kicks his WebTV around with a large trout
Originally posted by philsown
You can have multiple submit buttons on a form, just give them all the same name. If a submit button has no name, it's not passed to the action script.
Naming your buttons certainly makes sense for enabling getting a handle on them, but there is no real need to name them the same. I happen to find giving them the same names simpler, but some applications find it makes sense to name them different. Google, for instance.
One caveat: On many visual browsers, the button has to actually be clicked with the mouse; you can't just click the "return" key or neither submit button is passed.
That is a good point to mention regarding using multiple submit buttons, the only reliable behavior is to click on the chosen button. Using IE I have found that the button that gets passed is the one either prior or closest to the area having focus when the user hits 'return', apparently even if the button is on another form! To minimize unpredictable behavior I try to put the submit button just previous to the area likely to have focus for the action corresponding with it, but it is still something that needs to be kept in mind on the validation script, and something you need to play with when test driving the application.
create 2 form in one page, a form for a button, so u can post 2 different data to diffrent page.
create 2 form in one page, a form for a button, so u can post 2 different data to diffrent page.
A form for a button?!? If you mean nested form, it's better to avoid this technique.
This thread almost got to my problem -
I want to put 2 (unnested) forms on one page because I need to get an answer from a drop-down on the first form before I can ask the 2nd question - kind of like a tree root. I could do this with 2 pages, but it hardly justifies using 2 pages for so little data. Also, some members will arrive at the page with the 1st answer predefined and I can bypass displaying the first form for these people.
My problem is "how to get from a submit of the 1st form - to the 2nd form".
I have tried action="<?= $PHP_SELF ?>" and action="". But both seem to return to the top of the submitted form and reset the values to their original values. I am not able to get from the 1st form to the second form.
An alternative approach would be to use one form which would allow me to access the 1st answer (a drop-down) in order to set-up the appropriate drop-down for the 2nd question - this would be the preferable approach.
Both drop-downs are loaded with data from the member's db tables.
THANKS for any advice.
I am not sure how you are passing the 'predefined info' but to populate the second form with information from the first form using PHP you need to submit it to the form. You can do it on one PHP page using if statements:
if (no form submitted AND no predefined info exists)
..display form one
elseif (form one is submitted OR predefined info exists)
..process form one or gather predefined data
..display form two based on submitted data
elseif (form two is submitted)
..process form two
The above structure is simplified, you would probably structure it quite a bit differently for error trapping and to re-display an improperly entered form, but it should give you a general idea.
To do it all dynamically on one page and one submission you would need to use client side scripting, but the wisdom of relying on client side scripts for site functionality is questionable in most cases.
THANKS For your very prompt response. I will work on it tonight.
Some background:
Most members have only one "root system", therefore (except for new, additional systems), I know which of their "root systems" they want to update. Thus - the "predefined information" from their personal db tables.
The question, therefore, dealt with the remaining members and identifying which of their "root systems" (form 1) they wanted to work on and then (form 2) selecting the data from their tables that they want to update. All members will go through form 2.
THANKS again!
There might be a logic error in my simplified solution, depending on how you are gathering the predefined info it might show form two regardless with the ifelse structure
elseif (form one is submitted OR (predefined info exists && form two not submitted) )
Your final structure will probably have its own personality, anyway, though.
Good luck
THANKS for your followup.
Your suggestion is basically what I have been trying. Actually, my question is more of an HTML question - what to put in the ACTION atribute with the FORM tag. I have tried $PHP_SELF and spaces, but both appear to start at the top of form one again.
THANKS!!
Since it is a self posting form, you could leave the action attribute blank or insert PHP_SELF. If it is displaying form one again, then you have a logic error.
Form one should only be displayed of no form was submitted and no user info exists, so if you were following my example
if (no form submitted AND no predefined info exists)
to be more exact it would mean explicitly checking for each form
if (not form one && not form two && no predefined info)
So if any form was submitted, form one cannot be displayed.
Bear in mind, the structure I showed you was the simplest way to explain the process, but is not the way I would actually build it. That structure will work, but will get tricky doing error trapping if you need to re-display improperly filled out forms. If I were actually building it, I would probably process the forms before I displayed anything, then initialize flags to determine what to display after the processing is done.