am I missing something? validate empty input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

am I missing something? validate empty input

Post 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...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Whats the value of username before the validation check ? echo $_POST['username'];
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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;
}
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Dude, empty().
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Everah wrote:Dude, empty().
:cry:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It's all good.
Post Reply