zkwbbr/validation-helper

There is no license information available for the latest version (v1.0.0) of this package.

Helper class for Respect\Validation

v1.0.0 2019-03-30 15:08 UTC

This package is auto-updated.

Last update: 2024-03-29 03:32:52 UTC


README

Helper class for Respect\Validation

Install

Install via composer as zkwbbr/validation-helper

Sample Usage

<?php

use Zkwbbr\ValidationHelper;
use Respect\Validation\Validator as v;

$rules = [
    'foo' => v::email()->contains('.'),
    'bar' => v::numeric()
];

$data = [
    'foo' => 'fooValue',
    'bar' => 'barValue'
];

// init validation helper
$vH = new ValidationHelper\Helper;
$vH->setErrorsHtmlWrap('<div class="myerror">|</div>');

// get all failed rules in all fields
$errors = $vH->allErrors($rules, $data);
print_r($errors);

// get first failed rules in all fields
$errors = $vH->oneError($rules, $data);
print_r($errors);

// get first failed rules in all fields with error messages wrapped in HTML code
$errors = $vH->oneErrorHtmlWrap($rules, $data);
print_r($errors);