tags:

views:

228

answers:

7

hey guys

is it possible to have two forms with two submit buttons but when i click on the button then it saves both forms input fields

im concerning to solve this in php /mysql

i tried my own way :

if ((isset($_POST["form-1"])) && (isset($_POST["form-2"])) {
//SQL Insertion 
}

thanks in advance

A: 

You could submit both forms at the same time via Ajax but your php script would only receive one form at a time. Better to just convert your 2 forms into one big form if you need all inputs going to one script

rojoca
+3  A: 

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

If you have to use two forms, the only way to do this would be to clone the second form's fields into the first one using jQuery. Won't work when JS is turned off, though.

See Copying from form to form in jQuery

Why do you need two forms?

Pekka
actually i should use two forms , because the original scripts , im working with, require two different forms and i cant combine them into a unit one , how is the way in jquery !?
Mac Taylor
Perffect........
OM The Eternity
*(nitpicking)* you don't need jQuery to combine the forms. Can be done with JavaScript alone, too ;)
Gordon
@Gordon true. The jQuery virus is getting to me. I am spending too much time on SO. :)
Pekka
@Mac check out the link in my updated answer.
Pekka
@Pekka judging by your reputation gain since you registered, I can very much second that ;)
Gordon
No Not Again For Jquery Yes!! Or Jquery No!!!
OM The Eternity
@Gordon true... but it was worth it! I've learned a ton as well. :)
Pekka
@pekka ... Thanks man , u r my hero , love u :D
Mac Taylor
@Pekka And The Legendary Potter Borns Again He Is A Hero For MAC...
OM The Eternity
@Parth Stop Spamming :D
Mac Taylor
@MAC UR WISH IS MY COMMAND :D
OM The Eternity
A: 

As far as i know only one form can be submitted at a time. You could try wrapping them in one form.

Rob
A: 

A submit button submits only fields of the form it lives in. If you need content of both forms, you'll have to copy the fields from other form to some hidden field in the form where submit button was clicked. This can quite easily be done in JavaScript.

naivists
+3  A: 

If you have a problem like this, the design is flawed.

You can submit only one form at a time for a reason.

Change the design to use only one form; doing workarounds to submit two anyway is a horrible practice that would be better to avoid.

Lo'oris
A: 

One way of achieving similar result would be to club the two forms into a single one and have 2 submit buttons with different values and 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 
}
?>
Kalyan
A: 

The solution works well. I found another method with php form. All you need to do is juct copy the code.