Menu

Simple Field Validation
Setup vield validation with Leaf's simple validation tests

Intro

Leaf v1.4.2 has introduced a new Leaf Form module which is the replacement for Simple Validation from v1.2.0 which was discontinued in v1.3.0. Leaf Form contains methods to handle input from the user...

To use Leaf Form, you simply have to import it:

$form = new Leaf\Core\Form;

Leaf Form Methods

sanitizeInput

sanitizeInput offers basic security for input data, i.e. sanitizing input against SQL injection.

$username = $form->sanitizeInput($username);

isEmpty

isEmpty checks a field to see if it's empty. If it's empty, it adds an error to Leaf Form's errors. It takes in 3 parameters: the data to test, the name of that data and the error message if it's empty(optional).

$form->isEmpty($username, "username"); // error will be: This field is required $form->isEmpty($username, "username", "Username is required");

isNull

isNull checks a field to see if it's null. If it's null, it adds an error to Leaf Form's errors. It takes in 3 parameters: the data to test, the name of that data and the error message if it's empty(optional).

$form->isNull($username, "username"); // error will be: This field cannot be null $form->isNull($username, "username", "Username can't be null");

returnErrors

Remember we talked about Leaf Form errors? Leaf Form holds errors for all failed tests, you get all these errors back with returnErrors

$form->isNull($username, "username", "Username can't be null"); $errors = $form->returnErrors(); return $errors;