Unique registration number
For more information about adding custom validation rules, please read the following article: Adding custom validation rules to RSForm!Pro (article)
In this article we will describe as an example how to ensure that the registry number is correct. For instance, if you enter a registration number, it must only allow a number which is on a predefined list (vice-versa it will not allow a number which is not known) and these codes will not be visible to the public.
In order to achieve this a new custom validation rule will have to be added to RSForm!Pro. Just edit the file /components/com_rsform/helpers/customvalidation.php and add the new validation function here (if you don't have this file, you'll have to create it exactly as instructed in the above mentioned article):
public static function registrationCode($value, $extra = null, $data = null) { // Define an array of valid codes $validCodes = array('AAA', 'BBB', 'CCC', 'DDD'); // If we find the $value in our array of $validCodes, the code is correct. // Please note that this is case sensitive, eg. if the user submitted "AAA" it will work, but "aaa" will not. if (in_array($value, $validCodes)) { return true; } else { return false; } }
Now a new validation rule will be selectable for your fields. You will just have to change the codes to the ones of your choice.
If you want a case insensitive function, you can use the one below:
public static function registrationCode($value, $extra = null, $data = null) { // Define an array of valid codes $validCodes = array('AAA', 'BBB', 'CCC'); foreach ($validCodes as $code) { // This makes both values lowercase, ie. the submitted value and our code. if (strtolower($value) == strtolower($code)) { // If they're a match, return true. return true; } } // When all of the above fails, the supplied code is incorrect, so we have to return false. return false; }
10 persons found this article helpful.
You Should Also Read
Plugin - Joomla! User Registration (Create custom user registration forms) HOT |
Create a Joomla! registration form with dynamic user group assignment HOT |