In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to verify the necessary fields in the form in PHP", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to verify the necessary fields in the form in PHP" this article.
PHP required fields
When we have to fill in the information in our daily registration, we have encountered the necessary fields, and the necessary fields must be filled in when we fill in the information, otherwise there is no way to pass.
In the previous article, we have introduced the validation rules of the form, in which we introduced in the example: name validation rules are required, E-mail validation rules are required, which must be a valid e-mail address (including'@ 'and'.'). Gender verification rules are necessary and one must be selected. This is the necessary field that belongs to our power.
In the example in the previous article, all the input fields are optional because we did not validate them. So how can we achieve the effect that required fields are required?
At this point we can add some new variables to the following code: $nameErr, $emailErr, $genderErr, and $websiteErr.
These error variables are displayed on the required fields. We also added an if else statement for each $_ POST variable. These statements check to see if the $_ POST variable is empty (using php's empty () function). If empty, the corresponding error message is displayed. If it is not empty, the data is passed to the test_input () function.
Let's take a look at the practical application of these variables:
The output is not currently visible, and this code needs to validate the form's data through the form code.
Name validation rules are required, and E-mail validation rules are required, which must be a valid e-mail address (including'@ 'and'.'). Gender verification rules are necessary and one must be selected.
Through the above code, we have not been able to show the error. If we submit the above code knowledge without writing anything in the name, mailbox and gender input boxes, the error message will be displayed on the page. If it is not blank, it will be verified, and then execute the contents of the lse statement. Then let's take a look at how to display the wrong message.
In the HTML instance form of, we add some scripts to each field, and each script displays an error message when the information is entered incorrectly. So that if the user submits the form without filling in the information, the error message will be output.
Let's take a look at how to display the wrong message through an example. Examples are as follows:
.error {color: # FF0000;} PHP verification instance
* required fields
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.