API16

JFormRuleEmail/test

From Joomla! Documentation

This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Syntax

Returns

mixed on invalid rule, true if the value is valid, false otherwise.

Defined in

libraries/joomla/form/rules/email.php

Importing

jimport('joomla.form.rules.email');

Source Body

publicfunction test(&$field,&$values){$return=false;$name=(string)$field->attributes()->name;$check=((string)$field->attributes()->unique=='true'||(string)$field->attributes()->unique=='unique');// If the field is empty and not required, the field is valid.if((string)$field->attributes()->required!='true'){// Get the data for the field.$value=array_key_exists($name,$values) ? $values[$name]:null;// If the data is empty, return valid.if($value==null){returntrue;}}// Check if we should test for uniqueness.if($check){$key=(string)$field->attributes()->field;$value=isset($values[$key]) ? $values[$key]:0;// Check the rule.if(!$key){returnnew JException('Invalid Form Rule :: '.get_class($this));}// Check if the username is unique.$db=&JFactory::getDbo();$db->setQuery('SELECT count(*) FROM `#__users`'.' WHERE `email` = '.$db->Quote($values[$name]).' AND '.$db->nameQuote($key).' != '.$db->Quote($value));$duplicate=(bool)$db->loadResult();// Check for a database error.if($db->getErrorNum()){returnnew JException('Database Error :: '.$db->getErrorMsg());}// Test the value against the regular expression.if(parent::test($field,$values)&&!$duplicate){$return=true;}}else{// Test the value against the regular expression.if(parent::test($field,$values)){$return=true;}}return$return;}