php校验表单检测字段是否为空的方法_PHP教程

WBOY
Libérer: 2016-07-13 10:01:32
original
1076 Les gens l'ont consulté

php校验表单检测字段是否为空的方法

 这篇文章主要介绍了php校验表单检测字段是否为空的方法,涉及php验证表单的技巧,非常具有实用价值,需要的朋友可以参考下

 

 

本文实例讲述了php校验表单检测字段是否为空的方法。分享给大家供大家参考。具体如下:

php校验表单,检测字段是否为空,当表单中有未填写的字段,则会显示错误信息。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Contact Information



php后端代码,保存为: ErrorCheck.php

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$errorcount=0;

if (!trim($_POST['nickname'])) {

echo "
Nickname is required.";

$errorcount++;

}

if (!trim($_POST['title'])) {

echo "
Title is required.";

$errorcount++;

}

if ($errors > 0)

echo "

Please use your browser's back button " .

"to return to the form, and correct error(s)";

?>

trim()函数可以去除字符串中的前后空字符

?

1

2

3

4

5

6

" " (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.

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/971944.htmlTechArticlephp校验表单检测字段是否为空的方法 这篇文章主要介绍了php校验表单检测字段是否为空的方法,涉及php验证表单的技巧,非常具有实用价值...
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!