english/libraries/joomla/form/form.php
/**
	 * Method to validate a JFormField object based on field data.
	 *
	 * @param   string  $element  The XML element object representation of the form field.
	 * @param   string  $group    The optional dot-separated form group path on which to find the field.
	 * @param   mixed   $value    The optional value to use as the default for the field.
	 * @param   object  $input    An optional JRegistry object with the entire data set to validate
	 *                            against the entire form.
	 *
	 * @return  mixed  Boolean true if field value is valid, JException on failure.
	 *
	 * @since   11.1
	 */
Method to validate a JFormField object based on field data.
@param   string  $element  The XML element object representation of the form field.
@param   string  $group    The optional dot-separated form group path on which to find the field.
@param   mixed   $value    The optional value to use as the default for the field.
@param   object  $input    An optional JRegistry object with the entire data set to validate
against the entire form.

@return  mixed  Boolean true if field value is valid, JException on failure.


Method to validate a JFormField object based on field data . @param string $element The XML element object representation of the form field . @param string $group The optional dot - separated form group path on which to find the field . @param mixed $value The optional value to use as the default for the field . @param object $input An optional JRegistry object with the entire data set to validate against the entire form . @return mixed Boolean true if field value is valid JException on failure .
protected function validateField($element, $group = null, $value = null, $input = null)
	{
		if (!$element instanceof JXMLElement) {
			return new JException(JText::_('JLIB_FORM_ERROR_VALIDATE_FIELD'), -1, E_ERROR);
		}
		$valid = true;
		$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
		if ($required) {
			if (($value === '') || ($value === null)) {
								if($element['message']) {
					$message = $element['message'];
				}
				else {
					if ($element['label']) {
						$message = JText::_($element['label']);
					}
					else {
						$message = JText::_($element['name']);
					}
					$message = JText::sprintf('JLIB_FORM_VALIDATE_FIELD_REQUIRED', $message);
				}
				return new JException($message, 2, E_WARNING);
			}
		}
		if ($type = (string) $element['validate']) {
			$rule = $this->loadRuleType($type);
			if ($rule === false) {
				return new JException(JText::sprintf('JLIB_FORM_VALIDATE_FIELD_RULE_MISSING', $rule), -2, E_ERROR);
			}
			$valid = $rule->test($element, $value, $group, $input, $this);
			if (JError::isError($valid)) {
				return $valid;
			}
		}
		if ($valid === false) {
						$message = (string) $element['message'];
			if ($message) {
				return new JException(JText::_($message), 1, E_WARNING);
			}
			else {
				return new JException(JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', JText::_((string) $element['label'])), 1, E_WARNING);
			}
		}
		return true;
	}
protected function validateField ( $ element , $ group = null , $ value = null , $ input = null ) { if ( ! $ element instanceof JXMLElement ) { return new JException ( JText :: _ ( 'JLIB_FORM_ERROR_VALIDATE_FIELD' ) , - 1 , E_ERROR ) ; } $ valid = true ; $ required = ( ( string ) $ element [ 'required' ] == 'true' || ( string ) $ element [ 'required' ] == 'required' ) ; if ( $ required ) { if ( ( $ value === '' ) || ( $ value === null ) ) { if ( $ element [ 'message' ] ) { $ message = $ element [ 'message' ] ; } else { if ( $ element [ 'label' ] ) { $ message = JText :: _ ( $ element [ 'label' ] ) ; } else { $ message = JText :: _ ( $ element [ 'name' ] ) ; } $ message = JText :: sprintf ( 'JLIB_FORM_VALIDATE_FIELD_REQUIRED' , $ message ) ; } return new JException ( $ message , 2 , E_WARNING ) ; } } if ( $ type = ( string ) $ element [ 'validate' ] ) { $ rule = $ this -> loadRuleType ( $ type ) ; if ( $ rule === false ) { return new JException ( JText :: sprintf ( 'JLIB_FORM_VALIDATE_FIELD_RULE_MISSING' , $ rule ) , - 2 , E_ERROR ) ; } $ valid = $ rule -> test ( $ element , $ value , $ group , $ input , $ this ) ; if ( JError :: isError ( $ valid ) ) { return $ valid ; } } if ( $ valid === false ) { $ message = ( string ) $ element [ 'message' ] ; if ( $ message ) { return new JException ( JText :: _ ( $ message ) , 1 , E_WARNING ) ; } else { return new JException ( JText :: sprintf ( 'JLIB_FORM_VALIDATE_FIELD_INVALID' , JText :: _ ( ( string ) $ element [ 'label' ] ) ) , 1 , E_WARNING ) ; } } return true ; }
Method to validate a JFormField object based on field data.
Method to validate a JFormField object based on field data .
// Make sure there is a valid JXMLElement. // Initialise variables. // Check if the field is required. // If the field is required and the value is empty return an error message. // Does the field have a defined error message?
 // Get the field validation rule. // Load the JFormRule object for the field. // If the object could not be loaded return an error message. // Run the field validation rule test. // Check for an error in the validation test. // Check if the field is valid. // Does the field have a defined error message?
