Ernster Posted August 19, 2007 Share Posted August 19, 2007 Hi there, I have two forms which I want to kind of merge...obviously the 2 forms have 2 different methods set eg <form method="post" action="blahblahblahblah target="_new"> Is it possible to have 1 submit button for the 2 forms...so when a user clicks the submit button, the 2 seperate form methods both work.. If so how would I write it...thanks very much Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 19, 2007 Share Posted August 19, 2007 easier to just use the one form then you wouldn't need the js to do it. Consider doing it that way and if you really can't then post back on here - in the javascript section. Quote Link to comment Share on other sites More sharing options...
Ernster Posted August 19, 2007 Author Share Posted August 19, 2007 Hi there thanks.. Yeah I want it as 1 form, but I tried doing it but it only procecced one of the form methods.. How do i make it process both of them at the same time? Quote Link to comment Share on other sites More sharing options...
dbrimlow Posted August 19, 2007 Share Posted August 19, 2007 The answer to your question is "no". You cannot have more than one action and/or method within one form tag - so having one submit perform multiple tasks is moot. HOWEVER! What TM was getting at, was to be creative in your coding of your processing page so it will perform specific tasks based upon what data the variables submitted to it contain. If a variable contains "W" data, do "X" output, if it contains "Y" data do "Z" output. Here is why it cannot be done as you ask: As you know, a form is an enclosed "tag" <form></form> It contains specific instructions for THAT and only THAT tag, such as: "method='post or get'" and "action='somepage.php'". It then contains "input" elements for which you assign named variables to contain data inputed. Then it uses a "submit" element to pass data contained within named variables to the processing page - that was specified in the "action='somepage.php'. The form then terminates with a closing tag. So <form method="post" action="somepage.php' target="_new"></form> is a closed tag only allowing one method, action and submit. It passes the input variables to one page for processing. It is in coding your processing page, as to what to actually DO with the data contained within the passed variables, where the skill and focus of php becomes flexible and quite powerful. Now, IF you happen to be trying to use one form to access TWO different databases, with different named variables that are incompatible, then you simply have no choice but to use two different form tags with two different actions (processing pages). I actually have this situation in my full time job. I administer a Huge real estate website. We have one database for apts for sale, and a completely different DB for apts for rent - the table structures for the databases are completely different. I cannot have one processing page interpret two different sets of posted variables at the same time, open/close both databases and perform advanced select queries on both based on the posted variables. Although, I CAN perform a limited query for some posted variables that may have fields in common between databases. But I would have to make it a generic "negative check. For instance, both databases have "Listing Numbers" that use 6 numbers; our Sales database uses a range of numbers that starts with 5 (eg: 512345) and our Rentals database uses a range of numbers that start with 9 (eg: 912345). So I have a "search by listing #" form on our home page with an action that goes to our sales database processing page. It does a quick check on the data within the variable and if it the first number greater than 5 it closes and switches to the rental database processing page. THIS IS NOT RECOMMENDED! LOL! There are so many things that could mess this up. What if our company needed more number (7 instead of 6)? What if we needed a new set for sales to start with 6 (because we had over 599999 listings)? It is inefficient, but it illustrates how one form can control the output from two different databases depending upon the data within the variable. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.