PHP isset function to verify sending does not work

I just discovered that the isset function no longer works with my registration forms. Very strange though, so I unbuttoned everything I had recently done to see if this was causing this, but no luck. If I remove isset and replace this:

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

it works! But I have two forms on the same page, so I need to check which one is submitted.

Here's the isset function:

 if (isset($_POST['submit_login'])) { 

And the submit button is just to let you know that it has the correct name;

 <input type="submit" name="submit_login" value="Login" class="buttonClassic"/> 

The unit for the register form is exactly the same, but with the name submit_reg .

the form:

 <form action="<?php echo htmlentities('Login'); ?>" method="post" id="login"> <p class="p1">Already signed up? Log in</p><hr/> <label for="email">Your email address </label><input type="email" required name="email" placeholder="Email" class="text" id="email"> <label for="password">Your password </label><input type="password" name="pass" required placeholder="Password" class="text" id="password"> <center><input type="submit" name="submit_login" value="Login" class="buttonClassic"/></center> <div class="center-align-text"> <p class="p3"><a href="passreset.html">Forgotten your password?</a></p> </div> </form> 

reg form:

 <form action="<?php echo htmlentities('Login'); ?>" method="post" id="register" > <p class="p1">New to NBS? Sign up, it free!</p><hr/> <label for="reg_email">What your email address? </label><input type="email" name="email" required placeholder="Email" class="text" id="reg_email"> <label for="reg_password">Choose a password </label><input type="password" required name="pass" placeholder="Password" class="text" id="reg_password"> <label for="reg_password2">Re-type password </label><input type="password" required name="pass2" placeholder="Re-type password" class="text" id="reg_password2"> <input type="checkbox" name="subscribed" value="subscribed" id="subscribed"><label for="subscribed">Yes, send me email updates from NewBorn Sounds. </label> <br/> <input type="checkbox" required="flag" name="terms" value="ticked" id="terms"><label for="terms">I agree to the <a href="Terms">terms & conditions</a>.</label> <center><input type="submit" name="submit_reg" value="Sign Up" class="buttonClassic"></center> </form> 

If you need to shout something else!

Oh, and I know that I can just submit the form to an external PHP script, but I really do not want to do this, because I would like the user input errors to be displayed on one page. I know that I can just use ajax, which I do, but I'm trying to keep javascript as an add-on and not reduce the user interface without js.

Full HTML:

 <div id="login_form_wrapper"> <form action="Login" method="post" id="login" novalidate="novalidate"> <p class="p1">Already signed up? Log in</p><hr> <label for="email">Your email address </label><input type="email" required="" name="email" placeholder="Email" class="text" id="email"> <label for="password">Your password </label><input type="password" name="pass" required="" placeholder="Password" class="text" id="password"> <center><input type="submit" name="submit_login" value="Login" class="buttonClassic"></center> <div class="center-align-text"> <p class="p3"><a href="passreset.html">Forgotten your password?</a></p> </div> </form> <form action="Login" method="post" id="register" novalidate="novalidate"> <p class="p1">New to NBS? Sign up, it free!</p><hr> <label for="reg_email">What your email address? </label><input type="email" name="email" required="" placeholder="Email" class="text" id="reg_email"> <label for="reg_password">Choose a password </label><input type="password" required="" name="pass" placeholder="Password" class="text" id="reg_password"> <label for="reg_password2">Re-type password </label><input type="password" required="" name="pass2" placeholder="Re-type password" class="text" id="reg_password2"> <input type="checkbox" name="subscribed" value="subscribed" id="subscribed"><label for="subscribed">Yes, send me email updates from NewBorn Sounds. </label> <br> <input type="checkbox" required="flag" name="terms" value="ticked" id="terms"><label for="terms">I agree to the <a href="Terms">terms &amp; conditions</a>.</label> <center><input type="submit" name="submit_reg" value="Sign Up" class="buttonClassic"></center> </form> </div> 
+4
source share
3 answers

maybe you could do something like this:

 if($_SERVER['REQUEST_METHOD'] == "POST"){ if (isset($_POST['submit_login'])) { //do something } else { //do something else } } 
+1
source

The form action must be a valid URL, for example. "/login.php".

Flags have either a given value (after checking), or they are not displayed at all. It is best to double check them: "isset ($ _ POST ['mycheckbox']) & 'value' == $ _ POST ['mycheckbox']".

Show us the php you use to evaluate the form.

0
source

Like this?

 <input type="submit" name="submit_reg" value="Sign Up" class="buttonClassic"> <?php if($_POST['submit'] == 'Sign Up'){ //do something } ?> 
0
source

Source: https://habr.com/ru/post/1483947/


All Articles