View Full Version : Many nulls in blank $_POST field..How?
oldsportbiker
05 Dec 2009, 11:58 PM
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.
Alan
06 Dec 2009, 12:46 AM
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 (http://www.php.net/manual/en/ref.var.php) that you should take a look at. :)
<?php
if(isset($_POST['field']) && !empty($_POST['field'])) {
$field = $_POST['field'];
}
else {
// error message
}
?>
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.