Startses Posted August 11, 2009 Share Posted August 11, 2009 I have a function that checks wether the form submitted an empty field or not, basically goes like this: index.php___________ check($_POST['formfield']) functions.php___________ function check($text){ if (empty($text)) return false; else return true; } but it ALWAYS returns true, as if there is something stored within the variable. is there something invisible to be erased from the $_POST variable so it can be empty? Link to comment https://forums.phpfreaks.com/topic/169830-variable-not-empty/ Share on other sites More sharing options...
WolfRage Posted August 11, 2009 Share Posted August 11, 2009 Use isset() and remove your redundant function. The functionality you want is provided by isset(). empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. Return Values Returns FALSE if var has a non-empty and non-zero value. The following things are considered to be empty: "" (an empty string) 0 (0 as an integer) "0" (0 as a string) NULL FALSE array() (an empty array) var $var; (a variable declared, but without a value in a class) Link to comment https://forums.phpfreaks.com/topic/169830-variable-not-empty/#findComment-895972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.