PHP code example of slick / validator

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

    

slick / validator example snippets


use Slick\Validator\StaticValidator;

if (StaticValidator::validates('notEmpty', $value) {
  // Some code with valid value
} else {
  print StaticValidator::getMessage(); // Print out validation messages
}


use Slick\Validator\StaticValidator;

$urlValidator = StaticValidator::create('notEmpty', 'You must enter a valid URL.');

if ($urlValidator->validates($_POST['url']) {
    // URL is valid use it...
} else {
    print $urlValidator->getMessage(); // Will print out 'You must enter a valid URL.'
}


use Slick\Validator\StaticValidator;
use Slick\Validator\ValidationChain;

$emailValidation = new ValidationChain();
$emailValidation
    ->add(StaticValidator::create('notEmpty', 'Email address cannot be empty.'))
    ->add(StaticValidator::create('email', 'The entered e-mail is not a valid address.');
    
if ($emailValidation->validates($_POST['email']) {
    // URL is valid use it...
} else {
    print implode(', ', $emailValidation->getMessages()); 
    // Will print out the validation messages for the validator(s) that fail.
}