Page 1 of 1

am I missing something? validate empty input

Posted: Fri Aug 18, 2006 9:34 pm
by GeXus

Code: Select all

<?
class Validation{

	function isNotEmpty($f){
		if (strlen($f < 0))	
			return (false);
		else
			return (true);
			
	}
}
?>

Code: Select all

if ($validate->isNotEmpty($_POST['username']))
	{
		$smarty->assign('validationError', 'Please create a username below');
	}

Is there something wrong with this? No matter what it always returns false...

Posted: Fri Aug 18, 2006 9:48 pm
by anjanesh
Whats the value of username before the validation check ? echo $_POST['username'];

Posted: Fri Aug 18, 2006 9:51 pm
by GeXus
anjanesh wrote:Whats the value of username before the validation check ? echo $_POST['username'];
The value is there, its 'asdfasdf' which is what I happen to have entered. Also if I just do

Code: Select all

if(strlen($_POST['username'] < 0))
{
echo "validation";
}
that works fine... so i think it's something with the class... I do have other functions within that class that are working just fine however.

Posted: Fri Aug 18, 2006 9:54 pm
by Jenk
you do realise you are checking the length of a boolean, right?

have a closer look..

Code: Select all

if ( strlen ( $f < 0 ) ) {
should be:

Code: Select all

if (strlen($f)) {
    return false;
}
or for semantics sake:

Code: Select all

if (strlen($f) < 1) {
    return false;
}

Posted: Fri Aug 18, 2006 9:57 pm
by GeXus
Jenk wrote:you do realise you are checking the length of a boolean, right?

have a closer look..

Code: Select all

if ( strlen ( $f < 0 ) ) {
should be:

Code: Select all

if (strlen($f)) {
    return false;
}
or for semantics sake:

Code: Select all

if (strlen($f) < 1) {
    return false;
}
Jenk.. Doh! I just realized that.... thanks!

Posted: Fri Aug 18, 2006 11:32 pm
by RobertGonzalez
Dude, empty().

Posted: Fri Aug 18, 2006 11:47 pm
by GeXus
Everah wrote:Dude, empty().
:cry:

Posted: Fri Aug 18, 2006 11:58 pm
by RobertGonzalez
It's all good.