Unfortunately, the username and password you have entered do not match!

Registration

Unfortunately, this username is already taken!

Unfortunately, this e-mail address is already used!

Please retype the verification code.

All fields are required

RSForm!Pro - Unique registration number

Unique registration number

For more information about custom validation rules, please read the following article: Addin custom validation rules to RSForm! Pro

In this article we will describe 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. It will not allow a number which is not known. These codes will not be visible to the public.

In order to achieve this a new validation rule will have to be added to RSForm! Pro. Just edit the file /components/com_rsform/helpers/validation.php and add the new validation function here:

 
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;
}
 
Feedback