Php verification form detection field is empty

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.