4

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>
22
  • just out of curiosity, do you have two separate-not nested forms? Commented Jun 1, 2013 at 14:40
  • @Fabio yes the forms are completely seperate Commented Jun 1, 2013 at 14:40
  • what a var_dump($_POST); prints if you try one form? Commented Jun 1, 2013 at 14:42
  • @str thanks for that. It returns an array with the username and password but no submit button, I guess that's the key to fixing this! Commented Jun 1, 2013 at 14:42
  • 2
    seems like your buttons are out of the forms Commented Jun 1, 2013 at 14:43

3 Answers 3

1

maybe you could do something like this :

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

}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

How this?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.