How to process 2 forms in a single html page using jquery and php


I have 2 forms in a single html page. The first form is for logging in and the other is for signing up.

The login form contains a submit button with aname="loginsubmit" attribute while the signup form contains a submit button with aname="signupbutton" attribute.

How can I detect which submit button was clicked with jQuery so that I can pass it off to PHP?




Try understanding this.

<form action="check_login.php" method="POST">
    ....// form elements
    <input type="submit" name="login" value="LOGIN" />

<form action="register.php" method="POST">
    ....// form elements
    <input type="submit" name="register" value="REGISTER" />

When you have 2 separate forms, change their action. As simple as that. If flow comes tocheck_login.php, the click is on login button.If flows comes toregister.php, then click is on register.


Suppose if the action of both the form is same, add the following code in form action file.

  if(isset($_POST['login'])) {
      // click is on login button

  if(isset($_POST['register'])) {
      // click is on register button

People are also looking for solutions to the problem: Run PHP function from parent file


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.