PHP form - required fields
I don’t know if you have noticed that when we go online, some websites require us to register an account. When we register an account, we need to fill in the information. If we have important information that we have not filled in, we will be prompted. We tell you what is required to be filled in. In this chapter, we will explain the required fields and error messages of the form.
PHP - Required fields
Required fields are what we must fill in when we fill in the information, otherwise there is no way to pass,
In the previous chapter we have introduced the validation rules of the form. We can see that the "Name", "E-mail", and "Gender" fields are required. Each field cannot be empty. This is what is required. field.
# Name | is required. +Can only contain letters and spaces|
Optional. If present, it must contain a valid URL | Comments |
In the previous section, all input fields were optional because we did not validate them.
In the following code we have added some new variables: $nameErr, $emailErr, $genderErr, and $websiteErr.. These error variables will be displayed on required fields. We also added an if else statement for each $_POST variable. These statements will check if the $_POST variable is empty (using PHP's empty() function). If it is empty, the corresponding error message will be displayed. If it is not empty, the data will be passed to the test_input() function:
The meaning of the above code is that if If we submit without writing anything in the three required fields of name, email, and gender, then the corresponding error message will be displayed on the page, which name is required and the email is required. If it is not blank, the verification will pass and the content in the else statement will be executed.
But the above code cannot display the error message. Let's look down.
#PHP - Display error message
Example
- Course Recommendations
- Courseware download
-
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watching -
ElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watching -
IntermediateIssue 22_Comprehensive actual combat
5521 people are watching -
ElementaryIssue 22_PHP Programming
5172 people are watching -
ElementaryIssue 22_Front-end development
8713 people are watching -
IntermediateBig data (MySQL) video tutorial full version
4525 people are watching -
ElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watching -
ElementaryGO Language Core Programming Course
2814 people are watching -
IntermediateJS advanced and BootStrap learning
2563 people are watching -
IntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watching -
IntermediateRedis+MySQL database interview tutorial
2963 people are watching -
ElementaryDeliver food or learn programming?
5708 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
Required. Must select a | |