PHP code example of gourmet / validation

1. Go to this page and download the library: Download gourmet/validation 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/ */

    

gourmet / validation example snippets


public function validationDefault(Validator $validator)
{
    $validator
        ->provider('respect', new \Gourmet\Validation\Validation\RespectProvider())
        ->provider('iso', new \Gourmet\Validation\Validation\IsoCodesProvider())

        ->add('country_code', 'valid', [
            'provider' => 'respect',
            'rule' => 'countryCode',
        ])

        ->add('zip_code_by_country_code', 'valid', [
            'rule' => function($value, $context) {
                $provider = $context['providers']['respect'];
                $country = $context['data']['country_code'];
                return $provider->__call('postalCode', [$value, $country]);
            }
        ])

        ->add('zip_code_by_country', 'valid', [
            'rule' => function($value, $context) {
                $provider = $context['providers']['iso'];
                $country = $context['data']['country'];
                return $provider->__call('zip_code', [$value, $country]);
            }
        ])

        ->add('book_code', 'valid', [
            'provider' => 'iso',
            'rule' => 'isbn10'
        ])
}