Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit two forms with one button

I have HTML two forms, one that submits data upon entry to a database using PHP, the other directs the user to a paypal payment page, my problem is that the user would have to submit both forms which of course I do not want them to have to do. Is there anyway to use one submit button for two forms?

(Javascript is welcome)

like image 715
Alex Saidani Avatar asked Oct 20 '11 23:10

Alex Saidani


People also ask

Can we have 2 submit buttons in a form?

yes, multiple submit buttons can include in the html form. One simple example is given below.

How do you submit multiple forms to one button in react?

Well, If you are sending both these forms in the same request, then you can make a form object inside the parent component and then pass the form object to the children form and bind it. And then on Submit just post the data which is in the object.

How can I submit multiple PHP forms into one button?

First form is embed form from external website (vTiger webform) with action="https://***/crm/modules/Webforms/capture.php" method="post" Second form is FormIt-based form with preHook, which generate “form name”, “user_id” and “form_id” (value from TV). I save data from this form in another column is SQL-db.

How do I use multiple submit buttons in one form?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.


1 Answers

You should be able to do this with JavaScript:

<input type="button" value="Click Me!" onclick="submitForms()" /> 

If your forms have IDs:

submitForms = function(){     document.getElementById("form1").submit();     document.getElementById("form2").submit(); } 

If your forms don't have IDs but have names:

submitForms = function(){     document.forms["form1"].submit();     document.forms["form2"].submit(); } 
like image 182
James Johnson Avatar answered Oct 01 '22 21:10

James Johnson