


How to use the empty() function to determine whether the form text box input is empty?
In website program development, there are many web data submission pages. The simplest one is the login page. When we enter and submit content in the text box of the login page, it is not allowed to be empty. In addition to controlling the text box not to be empty through JavaScript scripts on the client, we can also make judgments on the server.
We generally verify the form once in the front end and once in the back end.
If you want to determine whether the value submitted by the form is empty on the server side, you can use the empty() function to check whether the variable is empty. Is empty, returns true if the variable is empty or zero. When the variables are: "", 0, "0", null, false, array(), var $var and objects without any attributes, they are considered empty. The syntax of the empty() function is as follows:
bool empty ( mixed $var )
The parameter var is the input variable
Application exampleUse the empty() function to verify login Whether the user name in the page is empty, the code is as follows,
The first is the login page code, the code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form action="login.php" method="post" onsubmit="return foo();" name="myform" > <div class="container"> <div class="right"> <h2 id="用户登陆">用户登陆</h2> <p> 用户名:<input type="text" name="user" id="name" > </p> <p> 密 码:<input type="password" name="password" id="pwd"> </p> <p><input type="hidden" value="hadden" name="hadden"></p> <p> <button class="button">立即登陆</button> </p> </div> </div> </form> </body> </html>
The code running result is as follows:
Code for server-side verification using the empty() function:
<?php header("content-type:text/html;charset=utf-8"); $user=$_POST['user']; $password=$_POST['password']; if(empty($user) || empty($password['password'])){ echo "用户名或密码不能为空<br/> <a href='login.html'>返回</a> "; }else{ echo "输入的用户名为 $user 密码为:$password"; } ?>
When the username and password text boxes are empty, click the Login Now button to verify the submitted form information , the running result is as follows:
#The above is a simple example where the empty() function checks to be empty. I hope everyone can understand it
The above is the detailed content of How to use the empty() function to determine whether the form text box input is empty?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement page jump after PHP form submission [Introduction] In web development, form submission is a common functional requirement. After the user fills out the form and clicks the submit button, the form data usually needs to be sent to the server for processing, and the user is redirected to another page after processing. This article will introduce how to use PHP to implement page jump after form submission. [Step 1: HTML Form] First, we need to write a page containing a form in an HTML page so that users can fill in the data that needs to be submitted.

How to use JavaScript to realize the automatic prompt function of the input box content of the form? Introduction: The automatic prompt function of the form input box content is very common in web applications. It can help users quickly enter the correct content. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Create the HTML structure First, we need to create an HTML structure that contains the input box and the auto-suggestion list. You can use the following code: <!DOCTYP

How to handle user rights management in PHP forms With the continuous development of web applications, user rights management is one of the important functions. User rights management can control users' operating rights in applications and ensure the security and legality of data. In PHP forms, user rights management can be implemented through some simple code. This article will introduce how to handle user rights management in PHP forms and give corresponding code examples. 1. Definition and management of user roles First of all, defining and managing user roles is a matter of user rights.

How to use JavaScript to implement real-time verification of the input box content of a form? In many web applications, forms are the most common way of interaction between users and the system. However, the content entered by the user often needs to be validated to ensure the accuracy and completeness of the data. In this article, we will learn how to use JavaScript to implement real-time verification of the content of the form's input box and provide specific code examples. Creating the form First we need to create a simple table in HTML

How to use HTML, CSS and jQuery to implement the advanced function of automatic saving of forms. Forms are one of the most common elements in modern web applications. When users enter form data, how to implement the automatic saving function can not only improve the user experience, but also ensure data security. This article will introduce how to use HTML, CSS and jQuery to implement the automatic saving function of the form, and attach specific code examples. 1. Structure of HTML form. Let’s first create a simple HTML form.

This article will explain in detail how PHP determines whether a specified key exists in an array. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP determines whether a specified key exists in an array: In PHP, there are many ways to determine whether a specified key exists in an array: 1. Use the isset() function: isset($array["key"]) This function returns a Boolean value, true if the specified key exists, false otherwise. 2. Use array_key_exists() function: array_key_exists("key",$arr

PHP form processing: form data query and filtering Introduction In Web development, forms are an important way of interaction. Users can submit data to the server through forms for further processing. This article will introduce how to use PHP to process the query and filter functions of form data. Form design and submission First, we need to design a form that includes query and filter functions. Common form elements include input boxes, drop-down lists, radio buttons, check boxes, etc., which can be designed according to specific needs. When the user submits the form, the data will be sent to POS

Forms are an integral part of writing a website or application. Laravel, as a popular PHP framework, provides rich and powerful form classes, making form processing easier and more efficient. This article will introduce some tips on using Laravel form classes to help you improve development efficiency. The following explains in detail through specific code examples. Creating a form To create a form in Laravel, you first need to write the corresponding HTML form in the view. When working with forms, you can use Laravel
