watagal Posted May 12, 2008 Share Posted May 12, 2008 Greetings--I'm not sure if anything is wrong or this is normal behavior? But when a checkbox is unchecked, it returns a null value (generating the notices in the output window)My HTML: <input class="checkbox" type="checkbox" name="chkRememberUserName" tabindex="3" value="OFF"> My PHP code which is called on form's submittal: echo 'chkRememberUserName = '.$_POST['chkRememberUserName'].'<br />';echo 'chkRememberPassword = '.$_POST['chkRememberPassword'];$postRememberUserName = $_POST['chkRememberUserName'];$postRememberPassword = $_POST['chkRememberPassword']; Output: chkRememberUserName = chkRememberPassword = onNotice: Undefined index: chkRememberUserName in D:\xampp\htdocs\_mysites\ck.com\Html_php_code\processSignIn.php on line 13Notice: Undefined index: chkRememberUserName in D:\xampp\htdocs\_mysites\ck.com\Html_php_code\processSignIn.php on line 15 Can someone confirm this or let me in on the fix?TiA, Gal Link to comment Share on other sites More sharing options...
jeffman Posted May 12, 2008 Share Posted May 12, 2008 Yup. This is where we use those wonderfully special php routines isset() and empty(), thus:if (isset ($_POST['galsval']) && !empty($_POST['galsval']) ) {// do something swell}And yes, you'll want to do this for every post and get variable, but after a while, it's just cut and paste. Link to comment Share on other sites More sharing options...
aspnetguy Posted May 12, 2008 Share Posted May 12, 2008 Yup. This is where we use those wonderfully special php routines isset() and empty(), thus:if (isset ($_POST['galsval']) && !empty($_POST['galsval']) ) {// do something swell}And yes, you'll want to do this for every post and get variable, but after a while, it's just cut and paste.or better yet write a function to do itfunction postEmptyOrNull($var) { if (!isset ($_POST[$var]) || empty($_POST[$var]) ) { return TRUE; } return FALSE;} //use like this if(!postEmptyOrNull('galsval')) { //do something } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.