In need of validation...

Joomla > RSForms

KPS use RSForms Pro to create a variety of forms for clients. These have included to date contact forms, application forms, registration forms and forms for competition entries.

Customers often require extra validation on fields to ensure that what's being collected is correct.

The RSForms Documentation gives some details as how you can add custom validation rules to your RSForms installation.

In order to add a new validation rule, navigate in your Joomla file list, go to components/com_rsform/helpers/validation.php*. In this file you will find all the validation rules defined. In order to add a new validation rule, edit the file validation.php in the following manner:

  1. Add a new function that allows only one parameter. The name of the function will be the name of the validation rule, as displayed when adding a new component.
  2. On success, the function should return true. On fail, the function should return false.

So here's some examples of custom validation rules we've collected for various purposes

Validate a phone number (10 or 11 digits)

  • Original Source
  • In addition to the examples given in the link, this also validates Australian number formats and international number formats such as:
  • 03 90052088
  • +61 3 9005 2088
  • 0412 307 296
  • +61 412 307296
  • The format of the validation code has been updated to be compatible with the format shown for validation scripts in the RSForms Documentation.
function phone($phone,$extra=null)
{
$phone_2 = preg_replace('/[^0-9]+/', '', $phone );
if($phone_2=='') return true;
$len = strlen($phone_2);
if($len == 10 || $len == 11) {
return true;
} else {
return false;
}

}

*Note that in newer versions of RSForm Pro since this article was originally written, the validation.php file has changed locations.
Previously it was in components/com_rsform/controllers/validation.php.

 

Add comment


Security code
Refresh