Niixie Posted December 16, 2011 Share Posted December 16, 2011 Hello, I have a problem with my login form, when i press the submit button, it returns a valitation error that I made. The error message is triggered when the submit button isn't pressed, but the form still tries to submit. session_start(); include "sources/php/class.php"; $e = $_POST['loginname']; $p = $_POST['loginpass']; $s = $_POST['submit']; if(!isset($s)) { header('location: '.$_SESSION['psite'].'.php?p=error&ploca=login&pid=0'); exit(); } Heres a piece of my code, first i define the variables, then check if the button was pressed, but something is wrong there? - But what? Hope you can help me. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/ Share on other sites More sharing options...
coupe-r Posted December 16, 2011 Share Posted December 16, 2011 Try if(isset($_POST['submit'])) { echo 'here'; } if you see "here" on your page, you know you are inside the condition and you can then continue to code inside. You should then set your vars and anything else you need. Always make sure the condition works before you start anything else. Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298621 Share on other sites More sharing options...
Niixie Posted December 16, 2011 Author Share Posted December 16, 2011 I do not see the 'here' anywhere, thats the weird thing? My form <form action="login_attempt.php" id="login-form"> <fieldset> <div class="field"> <label>Email-addresse<br /></label> <input type="text" class="text" value="" name="loginname"/><br /> <label>Adgangskode</label> <input type="password" class="text" value="" name="loginpass"/><br /> <input type='hidden' name='submit2' /> <input type="submit" value="" class="submit" name="submit"/> </div> </fieldset> </form> Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298624 Share on other sites More sharing options...
coupe-r Posted December 16, 2011 Share Posted December 16, 2011 If your button name is submit, as soon as you press the button, you should see "here" in the top left of your browser... Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298626 Share on other sites More sharing options...
Niixie Posted December 16, 2011 Author Share Posted December 16, 2011 But i dont. Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298631 Share on other sites More sharing options...
coupe-r Posted December 16, 2011 Share Posted December 16, 2011 try making your form action action="", instead of action="login_attempt.php". Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298634 Share on other sites More sharing options...
Drongo_III Posted December 16, 2011 Share Posted December 16, 2011 OR you could dumb it down still further just to test it and do if(empty($_POST['loginname']) && empty($_POST['loginpass'])) { echo "Display form"; } else{ echo "process form data"; } I suggest this because sometimes white space can mean a var isset even when it's not Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298638 Share on other sites More sharing options...
Niixie Posted December 16, 2011 Author Share Posted December 16, 2011 I made some changes to the code snippet, and debugged it. This is the code. include "sources/php/class.php"; $e = $_POST['loginname']; $p = $_POST['loginpass']; $s = $_POST['submit']; if(empty($e) && empty($p)) { echo "Display form"; exit(); } else{ echo "process form data"; exit(); } if(!$s) { header('location: '.$_SESSION['psite'].'.php?p=error&ploca=login&pid=0'); $_SESSION['debug'] = 1; exit(); } And this is the result Undefined loginname undefined loginpass undefined submit Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298647 Share on other sites More sharing options...
coupe-r Posted December 16, 2011 Share Posted December 16, 2011 Look are your <form> You don't have it set to POST or GET... Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298669 Share on other sites More sharing options...
Niixie Posted December 16, 2011 Author Share Posted December 16, 2011 Even if I add method="POST" in the form, it doesn't work. This is my form <form action="login_attempt.php" id="login-form" method="POST"> <fieldset> <div class="field"> <label>Email-addresse<br /></label> <input type="text" class="text" value="" name="loginname"/><br /> <label>Adgangskode</label> <input type="password" class="text" value="" name="loginpass"/><br /> <input type="submit" value="" class="submit" name="loginsubmit"/><a href="register.php"><img style="margin-top:5px;margin-left:5px;" src="images/opret-bruger.gif" width="70" height="16" alt="opret-bruger"/></a> </div> </fieldset> </form> And heres all my login_attempt.php session_start(); $e = $_POST['loginname']; $p = $_POST['loginpass']; $s = $_POST['submit']; if(!$s) { header('location: login.php?p=error&ploca=login&pid=0'); // This is what it returns all the time. exit(); } if(empty($e) || empty($p)) { header('location: login.php?p=error&ploca=login&pid=1'); exit(); } if(!validate::email($e)) { header('location: login.php?p=error&ploca=login&pid=2'); exit(); } if(mysql::is_registered($e)) { mysql::login($e, $p); } I can't see whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298677 Share on other sites More sharing options...
kicken Posted December 16, 2011 Share Posted December 16, 2011 $s = $_POST['submit']; You have no field in your form named submit. You named it loginsubmit: <input type="submit" value="" class="submit" name="loginsubmit" /> Quote Link to comment https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/#findComment-1298686 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.