Jacob Windsor
Jacob Windsor

Reputation: 6980

PHP isset function for submit check not working

I have just discovered that the isset function is no longer working on my login and register forms. Very strange I though, so I undid everything that I had recently done to see if it was causing it but no luck. If i remove the isset and replace with this;

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

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

Here's the isset function:

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

And the submit button just so you know it has the correct name;

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

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

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's free!</p><hr/>
   <label for="reg_email">What's 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 anything more just shout!

Oh and I know I could just submit the form to an external PHP script but I don't particularly want to do that as I would like the user input errors to be outputted to the same page. I know I could just use ajax, which I do, but I am trying to keep javascript as an add-on and not reduce the user experience for no 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's free!</p><hr>
   <label for="reg_email">What's 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>

Upvotes: 4

Views: 7718

Answers (3)

kathy
kathy

Reputation: 171

How this?

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

Upvotes: 0

Ryzal Yusoff
Ryzal Yusoff

Reputation: 1047

maybe you could do something like this :

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

}

Upvotes: 1

Zsolt Szilagyi
Zsolt Szilagyi

Reputation: 5006

Form action needs to be a valid url, e.g. "/login.php".

Checkboxes have either the value given (once checked), or they do not appear at all. Best is to double check them: "isset($_POST['mycheckbox']) && 'value' ==$_POST['mycheckbox']".

Show us the php you use to evaluate the form.

Upvotes: 0

Related Questions