mvader/formvalidator

Yet another php form validator.

Installs: 1

Dependents: 0

Stars: 3

Watchers: 1

Language: PHP

1.0.0 2013-11-18 19:36 UTC

README

Yet another php form validator.

Usage

<?php

use \FormValidator\Validator as Form;

$form = new Form();

$form->validate(
    'username',
    'lengthBetween',
    'The length of the username must be between 6 and 30.',
    array(6, 30)
);

$form->validate(
    'options',
    'valueIn',
    'Invalid value for the field.',
    array(array(1, 2, 3, 4))
);

$form->validate(
    'username', 
    function ($value) {
        return $value === 'my_username';
    },
    'Invalid username.'
);

$form->valideArray(array(
    array(
        'username',
        function ($value) {
            return $value === 'my_username';
        },
        'Invalid username.'
    ),
    array(
        'options',
        'valueIn',
        'Invalid value for the field.',
        array(array(1, 2, 3, 4))
    )
));

if (!$form->isValid()) {
    foreach ($form as $error) {
        echo $error . '<br />';
    }
}