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. 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. 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> 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... 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. 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". 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 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 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... 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? 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" /> 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
Archived
This topic is now archived and is closed to further replies.