mowgli
mowgli

Reputation: 2869

Check if specific form is submitted (in any way)

On my site I both have a login form, and a form for something else (this I all the second form)

They can both be present on the same page

How do I check if the second form is submitted?

I have learned that using this is good practice:

if (strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') { }

But this would also be true if the login form is submitted

How do I target (check if submitted) the second form and disregard the loginform? Should I check by it's name?

Upvotes: 2

Views: 1509

Answers (1)

cmbuckley
cmbuckley

Reputation: 42458

You can either have the forms have a different action, e.g. append ?action=login on the login form, or you can name the submit buttons something different on each form, e.g. <input type="submit" name="login" />. That way you can check isset($_REQUEST['login']) to see if it's the login form.

If a submit button is named in a form, it will be included in the POST however the form is submitted even if enter is pressed. If the form is sent via POST, then you can still include GET parameters in the form's action attribute, so either of these methods should do the job.

Upvotes: 5

Related Questions