Page 1 of 1

how to prevent empty posted forms

Posted: Sat May 16, 2009 12:46 pm
by rugbyfreak

Code: Select all

 
if ($name != " " && $familyname != " " && $user != " " && $email != " " && $password != " ");
{
    echo "The if statement evaluated to true";
} else {
    echo "The if statement evaluated to false";
}
 
i'm trying to prevent empty posted forms by looking if their are filling something. but it doesn't works. nee help
and if someone knows how to say that you must fill in at least x characters and at least filling an "@" in the email form. thank you

Re: how to prevent empty posted forms

Posted: Sat May 16, 2009 1:05 pm
by Benjamin
Please use

Code: Select all

tags when posting code and do not hijack other threads.  This question has been split from another users post.

Re: how to prevent empty posted forms

Posted: Sat May 16, 2009 1:15 pm
by Mark Baker
Shouldn't be a semi-colon after the if()
" " isn't empty, it contains a single space
Consider using trim to clear any number of leading or trailing spaces from a value

Code: Select all

if (trim($name) != "" && trim($familyname) != "" && trim($user) != "" && trim($email) != "" && trim($password) != "")
or empty()

Re: how to prevent empty posted forms

Posted: Sat May 16, 2009 1:17 pm
by Darhazer
You are checking if the variables are not a single space... and if I don't fill the field, you will receive "", not " "

You can use strlen() function to ensure that the field have at least x characters, and ereg / preg to check the e-mail format. Additionally, as of PHP 5.2 you can check the e-mail with filter_var($variable, FILTER_VALIDATE_EMAIL)

Re: how to prevent empty posted forms

Posted: Mon May 18, 2009 6:48 am
by rugbyfreak
thank you for the response:d:d

Re: how to prevent empty posted forms

Posted: Mon May 18, 2009 8:10 am
by rugbyfreak

Code: Select all

 
  if (strlen($name) == 0 || strlen($familyname) == 0 || strlen($user) < 6 || strlen($password) < 8) || !eregi('@',$email) 
   {
  header('Location:fillfields.html');
  }
  else
  {
  echo: "blabla";
  }
doesn't work...

Re: how to prevent empty posted forms

Posted: Tue May 19, 2009 3:30 pm
by Darhazer
Give a parse error?

If so, you just missed one more ')' at the end of first line.

Re: how to prevent empty posted forms

Posted: Wed May 20, 2009 5:41 am
by rugbyfreak
HTTP Error 404 Not Found

http://www.000webhost.com/

same with tha extr ')'

Re: how to prevent empty posted forms

Posted: Tue May 26, 2009 11:59 am
by rugbyfreak
does anyone knows an answer?

Re: how to prevent empty posted forms

Posted: Tue May 26, 2009 12:03 pm
by TheBrandon
Are you sure you have a "fillfields.html" on your site?

Re: how to prevent empty posted forms

Posted: Tue May 26, 2009 12:40 pm
by rugbyfreak
yes...