How to perfom 2 different actions using only 1 submit button on a form

I have a submit button for logging into my PHP/MySQL system. However, I would like to able to log in and at the same time take the credentials and store them in indexedDB when the button is clicked, is there any way of achieving 2 actions at the same time. So far if I include my javascript code for submitting to indexedDB, the login does not work, and if I remove the code, the login works.


If you want to save data in IndexedDB before logging in the user:

You can achieve this by calling a javascript function onSubmit. And inside that function, you can hit a GET/POST URL to save data in Indexed DB.

OR if you want to perform this task on the server side then One way of doing this is: Upon successful login or while verifying user's credentials, you can call a function to save data in your indexedDB. This function could be sync or async.

One form with two submit buttons and different actions for each , Multiple submit buttons php different actions And make sure you close your form with </form> – Redzwan Latif No JS, use HTML5. But I only used HTML5 formaction tag and now my form two submit button Button# 2. I have a form and I would like the ACTION field to be different depending on the button pressed. For instance the form might get processed by different PHP files if I press button A or button B.


What you could do is have your form take you to your first page, then do both the actions with all the data send to your form.

With a simple HTML/PHP form, this is simple. Submit the form to a new PHP page using action="submit.php". Then do your indexedDB call on this page, and echo out a copy of the form, complete with the data (POST or GET), but with your login page as the newactionthen echo a` tag like so:

echo "<script>document.getElementById('myForm').submit();</script>";

Then it will login via your login page.

Separate Form Submit Buttons That Go To Different URLs, Aug 2, 2017 Say you need another submit button that submits to a different URL. then check for that value when processing in order to do different things. <input type="submit" name="action" value="Value-1"> <input Another way was to use JavaScript to change the action of the <form> when the button was clicked. Say you have a form like this: <form action="/submit"> <!-- inputs and stuff --> <input type="submit" value="Submit"> </form> When you submit that form, it’s going to go to the URL `/submit`. Say you need another submit button that submits to a different URL. It doesn’t matter why.


onclick="doSomething();"

function doSomething(form){
// do something 
// do something else
// Finally submit the form
form.submit();
return true;
}

HTML forms with multiple submit buttons, Posted about 2 years ago. Visible to the public. button was pressed. To do so you can give each submit button a different [formaction] attribute. This will override the form's [action] attribute and hence cause the browser to POST the form to another URL. It is currently (0.62.1) not supported by Unpoly's form submission. Definition and Usage. The formaction attribute specifies where to send the form-data when a form is submitted. This attribute overrides the form's action attribute.. The formaction attribute is only used for buttons with type="submit".


seperate with two ;

onclick="doSomething();doSomethingElse();"

You're good to go!

Using multiple submit buttons on a single form, Using multiple submit buttons on a single form : Do you need to have more the script we're calling to handle the form submission or the ACTION attribute is " mulsub.asp") <INPUT type="submit" name="bsubmit" value="Submit 1"> The only difference is the "value" attribute with unique values -- "Submit 2" and " Submit 3� Form submitting data to new window and to two different pages We can use two different buttons to submit the form to two different pages. One of the buttons can submit the form in a new window. You can read the article on how to open the action page of the form in new window. This is required in different occasions where the visitor can see


HTML button formaction Attribute, The first submit button submits the form data to "action_page.php", and the second submits to This attribute overrides the form's action attribute. The formaction attribute is only used for buttons with type="submit". If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:. In this article, let’s see how to change this behaviour to post to different action methods when we have multiple submit button in a form in Asp.Net MVC application. Though we can do this in multiple ways, here we will discuss 2 primary methods, using HTML 5 formaction and another by using an ActionNameSelectorAttribute.


How to create a multi-submit form, You can use JavaScript to switch the action field of the form just when the What we will try to do in this post is still more adventurous: submitting the same form to multiple One occasion where this may be required is when you want to save the form The SubmitForm() function is called when submit button is pressed. While submitting the form it will fire the validation. Suppose we need to add another submit button on view and I want different functionality for that button, then it will call the same action method as the previous button, which means both buttons will point to the same action method.


How to Submit a Form with Multiple Buttons (Symfony Docs), When your form contains more than one submit button, you will want to check To do this, add a second button with the caption “Save and add” to your form:. Your <form> tag specifies the action to take when the submit button is pressed - but we can only specify a single action. A Solution One way to get around this is to handle each button's OnClick event and set the "action" for the form dynamically: