Originally Posted by
oldsportbiker
I've been stymied in trying to test for blank fields entered on an HTML form. All tests have been failing to identify a "blank", ( user entered nothing), field. I finally broke down the resultant $_POST variable in my called PHP and found that it's length was 11 characters and that each of those 11 characters was ascii 0 (null). While I could test on ascii values, I'm thinking I must be missing something since everything I've read makes it look like simple tests for if var =="". Any help here would be appreciated.
By default all fields in a form at not set, so the isset($_POST['field']) should return false.
If a user clicks inside a field, it is set but null. The empty($_POST['field']) should help you there. There are alot of variable handling functions that you should take a look at.
PHP Code:
<?php
if(isset($_POST['field']) && !empty($_POST['field'])) {
$field = $_POST['field'];
}
else {
// error message
}
?>
“The best thing about a boolean is even if you are wrong, you are only off by a bit.”