PHP FORM VALIDATION CHECK IF EMPTY HOW TO
->allowEmpty( boolean ): How to handle empty data (i.e.It has three methods that can be used to alter the validation behaviour: The ValidateOptions class is constructed with ValidateOptions::inst() (or new ValidateOptions() in PHP 5.4+) similar to the other Editor classes. This class defines a number of options that are shared between all validation methods. Validation optionsĮach validation method provided by the Validation class can optionally accept parameters to tell it how to validate data (for example the minLen method will accept an integer to indicate the minimum length of an acceptable string), but all optionally accept a ValidateOptions class instance. Please see below for more detailed examples. Each of these validation methods returns a function which is executed when required to validate submitted data.Ĭonsider the following example - the Validate::minNum() function is configured with a number and returns a function that can be used for the field validator. The Editor PHP libraries provide a validator() method for the Field class and a number of pre-built validation methods in the Validate class. Global validation can be useful when checking dependencies between fields and conflicts in the existing data set. The older form of validation will still work with the 1.7+ libraries and its documentation remains available, but for new projects use the validation style discussed here.įield validation is the one you will most commonly work with - for example checking that an e-mail address field actually contains an e-mail address, and Editor provides a number of ready to use validators for the most common data types as well as the ability to specify your own. Please note that PHP validation in Editor 1.6 and older was a little different.
![php form validation check if empty php form validation check if empty](https://i.stack.imgur.com/hK8GI.png)