sardonicgem Posted May 14, 2008 Share Posted May 14, 2008 Hey folks, Before I start implementing a real log-in page, I'm trying to get my self processing form to check for empty fields. Instead, the empty form keeps getting returned whether the fields were filled or not. I changed the form to use GET so I can see all the parameters for the time being. Upon submission, I can see the paramters being carried through, but it's like the logic checks are being ignored and the form re-renders. So according to this code, if the form is missing information, an error should be thrown, otherwise echo success. Why isn't it working??? <?php $in_name = $_GET["name"]; $in_pass = $_GET["pass"]; if (isset($_GET["submit"])) { if ((!isset($in_name))||(!isset($in_pass))) { ?> <p><font color="red><b>"Oops ...you did not fill out all your user credentials</b></font></p> <?php } else echo "success"; } else { // if page is not submitted to itself echo the form ?> <form action="<?php echo $PHP_SELF;?>" method="GET" id="identity"> <p>Please Login</p> <p> <label for="userName">Username: <input type="text" size="20" maxlength="20" id="userName" name="name"/></label></p> <p> <label for="password">Password: <input type="text" size="10" maxlength="10" id="password" name="pass"/></label></p> <p>New User? Click <a href="new.php">Here</a></p> <p><center><input type="submit" value="submit"></center></p> </form> <?php } Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/ Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 change this: <input type="submit" value="submit"> to this: <input type="submit" name="submit" value="submit"> Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540718 Share on other sites More sharing options...
sardonicgem Posted May 14, 2008 Author Share Posted May 14, 2008 wow. I cannot believe I missed that. Thanx Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540721 Share on other sites More sharing options...
sardonicgem Posted May 14, 2008 Author Share Posted May 14, 2008 So I enter only a username, or only a passoword or submit empty and I am receiving a successful response instead of the error. Any ideas? Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540725 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Because you are checking to see if $in_name and $in_pass are not set, but they are always set, because you are setting them at the top of your script. Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540727 Share on other sites More sharing options...
sardonicgem Posted May 14, 2008 Author Share Posted May 14, 2008 I thought isset returns TRUE if the variable contains a value other than NULL; FALSE otherwise Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540731 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Change if(!isset($in_name)) to if($in_name == "") Do the same with $in_pass. Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540734 Share on other sites More sharing options...
sardonicgem Posted May 14, 2008 Author Share Posted May 14, 2008 Haku ... you are a rockstar thanx. Now I need to convince myself why using the isset function was not logical Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540737 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 When you post (or get) something, a value is sent. It may be a value of nothing, but it's not a value of NULL (I have to admit, I'm not 100% sure what exactly IS passed though). You are setting the values of $in_name and $in_pass with the values that were passed. As such, the two variables were set. Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540739 Share on other sites More sharing options...
sardonicgem Posted May 14, 2008 Author Share Posted May 14, 2008 Thank you Haku. This my first time messing with PHP and you have been very helpful. How do I mark a post as resolved? Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540741 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 That's one I cant help you with! I know there is a way to do it, but I've never done it. There must be a checkbox somewhere. Link to comment https://forums.phpfreaks.com/topic/105554-self-processing-form-page-is-not-working-help/#findComment-540748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.