Jump to content

Possible to set multiple form methods? Please help.


Ernster

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.