PHP code example of poweronsystem / validationservice
1. Go to this page and download the library: Download poweronsystem/validationservice 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/ */
poweronsystem / validationservice example snippets
php
//Autoload composer
alidador (Ver archivo src/Validation.php)
$config = [
'return_boolean' => FALSE,
'date_format' => 'd/m/Y',
'date_time_format' => 'd/m/Y H:i',
'time_format' => 'H:i',
];
//Creamos una instancia del validador
$validator = new PowerOn\Validation\Validator($config);
//Creamos reglas de validación
$validator
->add('field_1', 'string_allow', ['alpha', 'spaces'])
->add('field_2', 'custom', function($value, $formData) {
//Lógica personalizada
return $value == 1 && key_exists('field_3', $formData) && $formData['field_3'] === 'some_value';
})
->add('field_2', 'decimal', 2)
->add('field_3', 'number', true, \PowerOn\Validation\Rule::WARNING);
//Datos obtenidos de un formulario
$data = [
'field_1' => 'campo-prueba',
'field_2' => 12.34,
'field_3' => 'some_value'
];
//Ejecuto la validación con los datos obtenidos
$validator->validate($data);
//Resultado
var_dump($validator->getErrors()); //array(size=1) 'field_1' => 'Este campo no admite: guiónes medios'
var_dump($validator->getWarnings()); //array(size=1) 'field_3' => 'Debe ser un valor numérico.'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.