这篇文章主要为大家详细介绍了php校验表单,检测字段是否为空的简单示例,具有一定的参考价值,可以用来参考一下。
对php校验表单,检测字段是否为空感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
<html>
<body>
<form METHOD="POST" ACTION="ErrorCheck.php">
<h1>Contact Information</h1>
<label>Nickname:</label>
<input TYPE="TEXT" NAME="nickname">
<label>Title:</label>
<input TYPE="TEXT" NAME="title">
<br />
<input TYPE="SUBMIT" VALUE="Submit">
<br />
<input TYPE="RESET" VALUE="Clear the Form">
</form>
</body>
</html>
php后端代码,保存为: ErrorCheck.php
/**
* php校验表单,检测字段是否为空
*
* @param
* @arrange 512-笔记网: www.q1010.com
**/
<html>
<body>
<?php
$errorcount=0;
if (!trim($_POST['nickname'])) {
echo "<br /><b>Nickname</b> is required.";
$errorcount++;
}
if (!trim($_POST['title'])) {
echo "<br /><b>Title</b> is required.";
$errorcount++;
}
if ($errors > 0)
echo "<br /><br />Please use your browser's back button " .
"to return to the form, and correct error(s)";
?>
</body>
</html>
/*** 来自四海网(www.q1010.com) ***/
trim()函数可以去除字符串中的前后空字符
/**
* php校验表单,检测字段是否为空
*
* @param
* @arrange 512-笔记网: www.q1010.com
**/
” ” (ASCII 32 (0×20)), an ordinary space.
“\t” (ASCII 9 (0×09)), a tab.
“\n” (ASCII 10 (0x0A)), a new line (line feed).
“\r” (ASCII 13 (0x0D)), a carriage return.
“\0″ (ASCII 0 (0×00)), the NUL-byte.
“\x0B” (ASCII 11 (0x0B)), a vertical tab.
/*** 来自四海网(www.q1010.com) ***/
本文来自:http://www.q1010.com/173/965-0.html
注:关于php校验表单,检测字段是否为空的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:表单
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。