PHP code example of zkwbbr / validation-helper

1. Go to this page and download the library: Download zkwbbr/validation-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zkwbbr / validation-helper example snippets




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);