New Feature: Custom validation rules
- Tuan Pham Ngoc
- Offline
- Administrator
Less
More
6 years 8 months ago #112831
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Hi Russ
Yes, the validation is for single field only. Maybe we in the parameter of my_custom_rule method, we can give access to other variables
- $fields: Array of fields use on the form
- $data: Array of field value
Base on that, you can perform the custom validation rule yourself? And instead of return false when not valid, you can return array of error messages? Will that work?
Tuan
Yes, the validation is for single field only. Maybe we in the parameter of my_custom_rule method, we can give access to other variables
- $fields: Array of fields use on the form
- $data: Array of field value
Base on that, you can perform the custom validation rule yourself? And instead of return false when not valid, you can return array of error messages? Will that work?
Tuan
Please Log in or Create an account to join the conversation.
- Russell Noble
- Offline
- Premium Member
Less
More
- Posts: 103
- Thank you received: 5
6 years 8 months ago #113060
by Russell Noble
Replied by Russell Noble on topic New Feature: Custom validation rules
Hi Tuan,
from my perspective it's just important to have access to the field contents, it's just that validating one field may require data from several fields. Sounds good.
Russ.
from my perspective it's just important to have access to the field contents, it's just that validating one field may require data from several fields. Sounds good.
Russ.
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
6 years 7 months ago #113462
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Hi Russ
Forgot to update that you can access to all form data in the custom validation rule, you can see it at eventbookingdoc.joomservices.com/basic-s...ld-custom-validators
Tuan
Forgot to update that you can access to all form data in the custom validation rule, you can see it at eventbookingdoc.joomservices.com/basic-s...ld-custom-validators
Tuan
The following user(s) said Thank You: Andrea
Please Log in or Create an account to join the conversation.
- Andrea
- Topic Author
- Offline
- Elite Member
6 years 7 months ago #113868
by Andrea
Visit my page! www.elementotango.it
Replied by Andrea on topic New Feature: Custom validation rules
For those Italians out there please find attached the validator php file that checks the "Codice Fiscale" (tax id number). Tested and working.
The php original function was freely available on the net, I just customized it to work with events booking.
Tuan again thanks!!
Andrea.
<?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;
class EventbookingHelperValidator
{
/**
* @param mixed $value Value of the custom field which this custom rule applied
* @param string $fieldName Name of the field
* @param RADForm $form The Form object
*
* @return bool|array true if valid, false if if in valid. You can also return an array of error messages if needed
*/
public static function check_cf($value, $codice_fiscale, $form)
{
if($value=='')
return false;
if(strlen($value)!= 16)
return false;
$value=strtoupper($value);
if(!preg_match("/[A-Z0-9]+$/", $value))
return false;
$s = 0;
for($i=1; $i<=13; $i+=2){
$c=$value[$i];
if('0'<=$c and $c<='9')
$s+=ord($c)-ord('0');
else
$s+=ord($c)-ord('A');
}
for($i=0; $i<=14; $i+=2){
$c=$value[$i];
switch($c){
case '0': $s += 1; break;
case '1': $s += 0; break;
case '2': $s += 5; break;
case '3': $s += 7; break;
case '4': $s += 9; break;
case '5': $s += 13; break;
case '6': $s += 15; break;
case '7': $s += 17; break;
case '8': $s += 19; break;
case '9': $s += 21; break;
case 'A': $s += 1; break;
case 'B': $s += 0; break;
case 'C': $s += 5; break;
case 'D': $s += 7; break;
case 'E': $s += 9; break;
case 'F': $s += 13; break;
case 'G': $s += 15; break;
case 'H': $s += 17; break;
case 'I': $s += 19; break;
case 'J': $s += 21; break;
case 'K': $s += 2; break;
case 'L': $s += 4; break;
case 'M': $s += 18; break;
case 'N': $s += 20; break;
case 'O': $s += 11; break;
case 'P': $s += 3; break;
case 'Q': $s += 6; break;
case 'R': $s += 8; break;
case 'S': $s += 12; break;
case 'T': $s += 14; break;
case 'U': $s += 16; break;
case 'V': $s += 10; break;
case 'W': $s += 22; break;
case 'X': $s += 25; break;
case 'Y': $s += 24; break;
case 'Z': $s += 23; break;
}
}
if( chr($s%26+ord('A'))!=$value[15] )
return false;
return true;
}
}
The php original function was freely available on the net, I just customized it to work with events booking.
Tuan again thanks!!
Andrea.
<?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;
class EventbookingHelperValidator
{
/**
* @param mixed $value Value of the custom field which this custom rule applied
* @param string $fieldName Name of the field
* @param RADForm $form The Form object
*
* @return bool|array true if valid, false if if in valid. You can also return an array of error messages if needed
*/
public static function check_cf($value, $codice_fiscale, $form)
{
if($value=='')
return false;
if(strlen($value)!= 16)
return false;
$value=strtoupper($value);
if(!preg_match("/[A-Z0-9]+$/", $value))
return false;
$s = 0;
for($i=1; $i<=13; $i+=2){
$c=$value[$i];
if('0'<=$c and $c<='9')
$s+=ord($c)-ord('0');
else
$s+=ord($c)-ord('A');
}
for($i=0; $i<=14; $i+=2){
$c=$value[$i];
switch($c){
case '0': $s += 1; break;
case '1': $s += 0; break;
case '2': $s += 5; break;
case '3': $s += 7; break;
case '4': $s += 9; break;
case '5': $s += 13; break;
case '6': $s += 15; break;
case '7': $s += 17; break;
case '8': $s += 19; break;
case '9': $s += 21; break;
case 'A': $s += 1; break;
case 'B': $s += 0; break;
case 'C': $s += 5; break;
case 'D': $s += 7; break;
case 'E': $s += 9; break;
case 'F': $s += 13; break;
case 'G': $s += 15; break;
case 'H': $s += 17; break;
case 'I': $s += 19; break;
case 'J': $s += 21; break;
case 'K': $s += 2; break;
case 'L': $s += 4; break;
case 'M': $s += 18; break;
case 'N': $s += 20; break;
case 'O': $s += 11; break;
case 'P': $s += 3; break;
case 'Q': $s += 6; break;
case 'R': $s += 8; break;
case 'S': $s += 12; break;
case 'T': $s += 14; break;
case 'U': $s += 16; break;
case 'V': $s += 10; break;
case 'W': $s += 22; break;
case 'X': $s += 25; break;
case 'Y': $s += 24; break;
case 'Z': $s += 23; break;
}
}
if( chr($s%26+ord('A'))!=$value[15] )
return false;
return true;
}
}
Visit my page! www.elementotango.it
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
6 years 7 months ago #113890
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Hi Andrea
I am sorry, I decided to use a new validation library for the extension in the next release 3.5.2, so the code for custom validation rule will have to be changed a bit. See eventbookingdoc.joomservices.com/basic-s...ld-custom-validators
So before updating to version 3.5.2, please adjust your custom rules you built for your site
Sorry for the inconvenience (the old library is very big and contains many unnecessary code), so I decided to switch to a lighter library for easier maintainance
Regards,
Tuan
I am sorry, I decided to use a new validation library for the extension in the next release 3.5.2, so the code for custom validation rule will have to be changed a bit. See eventbookingdoc.joomservices.com/basic-s...ld-custom-validators
So before updating to version 3.5.2, please adjust your custom rules you built for your site
Sorry for the inconvenience (the old library is very big and contains many unnecessary code), so I decided to switch to a lighter library for easier maintainance
Regards,
Tuan
Please Log in or Create an account to join the conversation.
- Andrea
- Topic Author
- Offline
- Elite Member
6 years 7 months ago #113892
by Andrea
Visit my page! www.elementotango.it
Replied by Andrea on topic New Feature: Custom validation rules
Hi Tuan, this is not too nice as poor people like me who don't know php very well (indeed not at all) spent the last night to create two new validation rules, which I have now to re-write.
Hopefully, the necessary modification won't be too complex to apply even for a php-ignorant like me, so at the end it's OK and I'll do it.
Don't change it another time !
Regards
Hopefully, the necessary modification won't be too complex to apply even for a php-ignorant like me, so at the end it's OK and I'll do it.
Don't change it another time !
Regards
Visit my page! www.elementotango.it
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
6 years 7 months ago #113893
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Only this time. And actually, it's not really re-write. Just paste your original code to new method syntax and it will be fine
Tuan
Tuan
Please Log in or Create an account to join the conversation.
- Andrea
- Topic Author
- Offline
- Elite Member
6 years 7 months ago #113896
by Andrea
Visit my page! www.elementotango.it
Replied by Andrea on topic New Feature: Custom validation rules
Hello Tuan, no issues.
Indeed, I have already changed my rules to the new format and tested them in the dev system. They're working fine, so I'm moving them into production.
It took me just a bunch a minutes.
Thanks!
Andrea
Indeed, I have already changed my rules to the new format and tested them in the dev system. They're working fine, so I'm moving them into production.
It took me just a bunch a minutes.
Thanks!
Andrea
Visit my page! www.elementotango.it
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
6 years 7 months ago #113900
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Great. Happy to hear that
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
6 years 7 months ago #113901
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic New Feature: Custom validation rules
Great. Happy to hear that
Please Log in or Create an account to join the conversation.
Moderators: Tuan Pham Ngoc
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.