Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit 2 forms with one button

Status
Not open for further replies.

wiser3

Programmer
Jun 3, 2003
358
CA
We're desinging a page with a large form and would like to have a sub-form. Can one submit button submit both forms to the same php script?

The user may fill out the full form and submit it. No problem. But we'd like to have a section of it as a sub-form. So, if they change and the sub-form and submit it the server reprocesses the data and returns the page with both the sub-form and larger form filled out as when submitted. A problem arises in that if they submit the sub-form how do we get the data from the large form to the server so we can repopulate those fields.

Perhaps if one form used the post method and the other get? But wouldn't that send two seperate streams to the server the get processed seperately?

Any thoughts or help would be appreciately.

Thanks
 
I don't quite understand the whole question, because of things like "So, if they change and the sub-form and submit it." But from what I think you're trying to say here's the best solution.

Make one large form for the whole page.
The design can make the user assume it is two forms when in fact it is one.
Use the POST method, and test for all of the variables you need using
Code:
$_POST['input_name']

When you go to write the PHP part that will process it, if you want to split the forms, then you can simply test for a unique input.

Code:
if($_POST['sub_form_input']) { //If the sub-form has been used
     //do something
} else { //If the sub-form is not used
     //do something
}

It's best to use one form in this case and in many, because in most cases the data only needs to be sent one place, the tricky part is simply learning how to handle and filter the data.

And to answer your question, yes, I think it is possible to submit 2 forms using javascript, but I've never used it, and I wouldn't suggest something like that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top