Php verification form detection field is empty
This article mainly introduces the php verification form Check Method to check whether the field is empty. It involves php verification form skills and is very useful. For more information, see
This example describes how to check whether a field in a php form is empty. Share it with you for your reference. The details are as follows:
Php verifies the form and checks whether the field is empty. If there are unfilled fields in the form, an error message is displayed.
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<Html> <Body> <Form METHOD = "POST" ACTION = "ErrorCheck. php"> <H1> Contact Information <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 back-end code, saved as: ErrorCheck. php
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<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/> Please use your browser's back button ". "To return to the form, and correct error (s )"; ?> </Body> </Html> |
The trim () function removes the trailing and trailing null characters in the string.
?
| 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. |
I hope this article will help you with php programming.