How to use two forms and send once?

Is it possible to have two forms with two submit buttons so that when the button is pressed, it saves the input fields in both forms?

I want to solve this in PHP / MySQL.

I tried in my own way:

if ((isset($_POST["form-1"])) && (isset($_POST["form-2"])) { //SQL Insertion } 
+5
html php mysql
source share
6 answers

No, you can only submit one form at a time.

If you need to use two forms, the only way to do this is to clone the fields of the second form into the first using jQuery. Doesn't work if JS is off.

See Copying from form to form in jQuery

Why do you need two forms?

+4
source share

If you have such a problem, the design has flaws.

You can submit only one form at a time.

Change the design to use only one shape; doing workarounds to represent the two anyway is a terrible practice that is best avoided.

+3
source share

One way to achieve a similar result would be to combine the two forms into one and two submit buttons with different values ​​and the same name="submit" field.

toFoo.html:

 <form action="doFoo.php"> User <input type="text" name="username" /> Pass <input type="password name="password" /> <!-- Submit one --> <input type="submit" name="submit" value="Create user" /> <!-- some more of your fields or whatever --> <input type="text" name="blah" value="bleh" /> <!-- Submit two --> <input type="submit" name="submit" value="Login user" /> </form> 

doFoo.php:

 <?php if( $_POST["submit"] == "Login user" ) { //do login foo } if( $_POST["submit"] == "Create user" ) { //do signup foo } ?> 
+1
source share

You can submit both forms at once via Ajax, but your php script will only get one form at a time. It’s better to just convert 2 forms into one big form if you need all the inputs going to the same script

0
source share

As far as I know, only one form can be presented at a time. You can try wrapping them in one shape.

0
source share

The submit button represents only the fields of the form in which it lives. If you need the contents of both forms, you will need to copy the fields from another form into some hidden field in the form that the submit button was clicked on. This is easy to do in JavaScript.

0
source share

All Articles