Beside client side validation, from version 2.14.0 of Membership Pro, you can also validate custom fields data using server side validation (using PHP code). You can use both built-in validators and implement custom validators yourself. To use server side validation, you can edit the custom field, enter the rules you want to use into Server Validation Rules
We use Valitron Validation library - the most awesome validation engine ever created for PHP for validating custom fields data in Events Booking. See https://github.com/vlucas/valitron#built-in-validation-rules for list of supported validators you can use.
The syntax which you can enter into Server Validation Rules is rule1|rule2:param1,param2. Basically:
Examples:
Sometime, you will need to build custom validator to validate the custom field data using the logic you want. To do that:
<?php
/**
* @package Joomla
* @subpackage Membership Pro
* @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 setup 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 a integer number between 10 and 20....