首页 / 操作系统 / Linux / 简单的服务器端表单数据验证代码
简单的服务器端表单数据验证代码
<?php
//echo $_REQUEST["first"]."<br>";
//echo $_REQUEST["last"]."<br>";
if ($_REQUEST["submit"]) {if (!$_REQUEST["first"] || !$_REQUEST["last"]) {
$error = "对不起,您必须填写所有的栏目!";
} else {
if ((strlen($_REQUEST["first"])<6 || strlen($_REQUEST["last"])<8)) {
$error= "请输入正确的数据。";
}
else {
echo "数据通过验证,谢谢!";
}
// 处理表格输入内容
}
}
if (!$_REQUEST["submit"] || $error) {
echo $error;
?>
<form method="post" action="<?=$_SERVER[PHP_SELF]?>">
第一栏: <input type="text" name="first" value="<?=$_REQUEST["first"]?>">(长度不少于6)<br>
第二栏: <input type="text" name="last" value="<?=$_REQUEST["last"]?>">(长度不少于8)<br>
<input type="Submit" name="submit" value="输入信息">
</form>
<?php
} // if结束
?>