Up to this point, everything we’ve talked about regarding the WordPress Settings API and saving data to the database has been based around two ideas:
- We need to sanitize the input
- We haven’t been concerned with any particular fields being required
At this point though, we’re ready to start talking about how to tackle this particular issue. Since we’re already familiar with how to sanitize the data, we’re going to build off of the code that we already have.
That is, we’re going to look at how to validate the following fields:
- Address 1
- City
- Postal Code
Furthermore, we’re going to see how to tackle this from an object-oriented approach, we’re going to look at what’s needed in order to add an error message if the required input is invalid, and we’re also going to look at how to prevent saving information to the database if it’s empty or invalid.