This chapter shows how to make input fields required and create error messages if needed
PHP – Required Fields
From the validation rules table on the previous page, we see that the “Name”, “E-mail”, and “Gender” fields are required. These fields cannot be empty and must be filled out in the HTML form.
Field | Validation Rules |
---|---|
Name | Required. + Must only contain letters and whitespace |
Required. + Must contain a valid email address (with @ and .) | |
Website | Optional. If present, it must contain a valid URL |
Comment | Optional. Multi-line input field (textarea) |
Gender | Required. Must select one |
In the previous chapter, all input fields were optional. Continue reading PHP Forms – Required Fields