如果填写表单,如何验证PHP

时间:2016-04-07 04:00:30

标签: php html testing

//所以我有一个外部的php验证和一个html文件。我正在尝试验证//输入框是否正确填写...到目前为止我有一个但我无法得到它//运行并且我尝试测试它不起作用...我做需要下载//某些东西或者我的代码是完全错误的。我只是想检查它是否为空,如果它至少有3个字符

<!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>

4 个答案:

答案 0 :(得分:1)

你可能正在寻找类似的东西:

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

答案 1 :(得分:0)

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

此外,它还要使用$ _POST或$ _GET而不是$ _REQUEST。

答案 2 :(得分:0)

我认为您正在寻找:

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

您可以确保isset()功能存在值。

答案 3 :(得分:0)

requird validation

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