Nette\Forms\Rules::addRule PHP Méthode

addRule() public méthode

Adds a validation rule for the current control.
public addRule ( $validator, $message = NULL, $arg = NULL ) : self
Résultat self
    public function addRule($validator, $message = NULL, $arg = NULL)
    {
        if ($validator === Form::VALID || $validator === ~Form::VALID) {
            throw new Nette\InvalidArgumentException('You cannot use Form::VALID in the addRule method.');
        }
        $rule = new Rule();
        $rule->control = $this->control;
        $rule->validator = $validator;
        $this->adjustOperation($rule);
        $rule->arg = $arg;
        $rule->message = $message;
        if ($rule->validator === Form::REQUIRED) {
            $this->required = $rule;
        } else {
            $this->rules[] = $rule;
        }
        return $this;
    }

Usage Example

Exemple #1
0
	/**
	 * Adds a validation rule.
	 * @param  mixed      rule type
	 * @param  string     message to display for invalid data
	 * @param  mixed      optional rule arguments
	 * @return FormControl  provides a fluent interface
	 */
	public function addRule($operation, $message = NULL, $arg = NULL)
	{
		$this->rules->addRule($operation, $message, $arg);
		return $this;
	}
All Usage Examples Of Nette\Forms\Rules::addRule