How can I use the empty () function to determine whether the input in the form text box is empty?

Source: Internet
Author: User
In website program development, there are many webpage data submission pages. The simplest is the login page, which cannot be blank when the input content is submitted in the text box on the login page. In addition to controlling the text box through JavaScript scripts on the client side, we can also make judgments on the server side. In website program development, there are many webpage data submission pages. The simplest is the login page, which cannot be blank when the input content is submitted in the text box on the login page. In addition to controlling the text box through JavaScript scripts on the client side, we can also make judgments on the server side.

Generally, form verification is performed once at the front end and once at the backend.

You can useEmpty () functionTo complete,

The empty () function checks whether the variable is null. if the variable is null or zero, true is returned. When the variables are: "", 0, "0", null, false, array (), var $ var, and objects without any attributes are considered null. The empty () function syntax is as follows:

bool empty ( mixed $var )

The var parameter is the input variable.

Application example

Use the empty () function to verify whether the username on the logon page is empty. the code is as follows,

The logon page code is as follows:

    
     First PHP community (php1.cn)

The code execution result is as follows:

Code for verification on the server side using the empty () function:

 Return ";} else {echo". The username is $ user. the password is $ password ";}?>

If the username and password text box is blank, click log on now to verify the submitted form information. the running result is as follows:

The above is a simple instance with the empty () function check being empty. I hope you will have some knowledge.

The preceding figure shows how to use the empty () function to determine whether the input in the form text box is empty? For more information, see other related articles in the first PHP community!

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.