Michele
Michele

Reputation: 19

How to validate php if form is filled

//So i have a php validation external and a html file. I'm trying to validate if //the input boxes are filled out correctly... so far i have one but I can't get it //to run and i tried testing it out doesn't work... do i need to download //something or is my code completely wrong. I just trying to check if its empty and if it has at least 3 characters

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cal5t</title>
</head>

<body>
<?php

$title= $_REQUEST["title"];
if ($title == "" or >3 ) {
echo "<p>5please!</p>";
?>
</body>
</html>

Upvotes: 0

Views: 69

Answers (4)

Xorifelse
Xorifelse

Reputation: 7911

if(!empty($title= $_POST['title']) && strlen($title) > 5){
  echo "valid: $title";
} else {
  echo "incorrect title: '$title'";
}

Also, its beter to use $_POST or $_GET over $_REQUEST.

Upvotes: 0

Subash
Subash

Reputation: 230

requird validation

$title = trim($_POST['title']); // it will remove stat and end spaces
if(strlen($title) <= 0)
{
     echo "Title Field is required";
}

Upvotes: 0

ProtectedMethod
ProtectedMethod

Reputation: 109

I think you're looking for:

if(strlen($title) < 5){
echo '<p>The title you entered is not long enough.</p>";
}

You can make sure there is a value with the isset() function.

Upvotes: 0

Mogens TrasherDK
Mogens TrasherDK

Reputation: 680

You are probably looking for something like:

if (($title == "") or (strlen($title) < 5))
{
   echo "<p>5please!</p>";
}

Upvotes: 1

Related Questions