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.
-
Possible duplicate of [Two submit buttons in one form](https://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form) – David R Feb 21 '19 at 07:58
-
@ David R, I want to have one submit button perfom 2 actions,not have 2 buttons on the same form – BLESSING Feb 21 '19 at 08:02
-
1Yes, there is: write the proper code for that. As you haven't shared your attempt, one could only guess where you are going wrong. After all: how is this related to PHP? – Nico Haase Feb 21 '19 at 08:43
4 Answers
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 new
actionthen echo a
` tag like so:
echo "<script>document.getElementById('myForm').submit();</script>";
Then it will login via your login page.

- 43,180
- 11
- 50
- 79
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.

- 108
- 2
- 15
-
thank you so much, your answer helped me a lot in solving my issue.I pulled the credentials after a successful login then used a javascript function to save them in indexedDB – BLESSING Feb 24 '19 at 19:11
onclick="doSomething();"
function doSomething(form){
// do something
// do something else
// Finally submit the form
form.submit();
return true;
}

- 51
- 4
-
1Please add some explanation to that code, such that others can learn from it – Nico Haase Feb 21 '19 at 12:49
seperate with two ;
onclick="doSomething();doSomethingElse();"
You're good to go!

- 1,727
- 9
- 22
-
Using `onclick` directly in the HTML tag is not really good practise. Instead, use a pure JS implementation to bind that handler to the according tag – Nico Haase Feb 21 '19 at 08:45