I had a problem with a piece of code i just developed and I have narrowed it down to the number 0 not being accepted.
This is the html
<input type="text" size="1" name="hs" maxlength='3'>
If I enter ZERO into that input box it gives an error saying nothing has been entered.
Once I have passed this through, this is the PHP error handling code
$field = "hs";
if((!$hs) || strlen($hs = trim($hs)) == 0)
{
$form->setError($field, "* Home score not entered");
}
$field = "as";
if((!$as) || strlen($as = trim($as)) == 0)
{
$form->setError($field, "* Away score not entered");
}
I am getting those errors if I enter the score at a 0.
Any ideas why this is happening?
Is it something any of you have experienced?
THanks
PHP interprets both the text string
'0‘ and the number0asfalse. Implicit type conversion is sometimes handy and sometimes annoying. (What you’re getting from the form is the string'0').Try something like