In addition to client side validation, Events Booking has supported server-side validation in PHP since version 3.5.0. You can use built-in validators or implement your own. To apply them to a field, edit the field and enter the rules in Server Validation Rules.
Events Booking uses the Valitron Validation library to validate custom field data. See https://github.com/vlucas/valitron#built-in-validation-rules for the built-in validators.
The syntax which you can enter into Server Validation Rules is rule1|rule2:param1,param2. Basically:
Examples:
To validate a field using your own logic, create a custom validator as follows.
<?php
/**
* @package Joomla
* @subpackage Event Booking
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2010 - 2018 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
defined('_JEXEC') or die;
Valitron\Validator::addRule('my_custom_rule', function($field, $value, array $params, array $fields) {
if (strlen($value) != 9)
{
return false;
}
return true;
}, 'The field must has exactly 9 characters');
Valitron\Validator::addRule('my_custom_rule2', function($field, $value, array $params, array $fields) {
if ($value != 9)
{
return false;
}
return true;
}, 'The field must has value = 9');
Each rule contains a block of code like that with the following parameters:
See https://github.com/vlucas/valitron#adding-custom-validation-rules for more detailed instructions from the original library
When data for a field is not valid, the system will show an error message to registrants so that they will know about the error and correct it. Yoi should set up a clear error message for the field in Validation error message setting like [FIELD_NAME] must be a string with maximum 20 characters..., [FIELD_NAME] must be an integer number between 10 and 20....