Unique email address validation rule

In order to accept only one submission per email address in your forms, a custom validation rule can be created and added in /components/com_rsform/helpers/customvalidation.php. Please firstly read the article on how to add custom validation rules in order to create the file and its structure before placing the custom validation rule.

The following function will check if the current value is unique:

 
public static function uniqueEmail($value, $extra = null, $data = null) {
      // The following will check if the current value is indeed an email
      if (!self::email($value, $extra, $data)) {
      return false;
      }
      // The following will check if the current value is unique (never submitted within that form)
      return self::uniquefield($value, $extra, $data);      
  }
 

After creating the validation rule and placing it in the customvalidation.php file, you will be able to select it when assigning the validation rule for your email address field in RSForm!Pro.

Note:
You can change the name of the function (in the example above is "uniqueEmail") in order to assign it a custom name of your choice.
This should be used as an example since RSForm!Pro incorporates a "Multiple Rules" validation rule which allows selecting, as suggested, multiple validation rules at once (this being said you can set the field validation to Multiple Rules and then select the Unique and Email validation rules).


7 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Add Terms and Conditions functionality

Display a message on the top side of the form if validation fails

Ajax validation is not working

RSForm! Pro regular expression (regex) validation does not work!

How do i validate special chars?