Example #1
0
 /**
  * Validate the entire form data set against each field's validators, and additionally validate interdependent fields.
  *
  * @return boolean True if each of the container's fields validates, and additionally if the dependencies validate; otherwise false.
  */
 public function isValid()
 {
     $valid = parent::isValid();
     $setPasswordField = $this->getField('setpass');
     if (!$setPasswordField->hasErrorMessage() && $setPasswordField->getData()) {
         $passwordField = $this->getField('pass');
         if (!$this->passwordLengthValidator->isValid($passwordField->getData())) {
             $passwordField->setErrorMessage($this->passwordLengthValidator->getErrorMessage());
         }
         $passwordAgainField = $this->getField('passagain');
         if (!$passwordField->hasErrorMessage() && !$passwordAgainField->hasErrorMessage()) {
             $password = $passwordField->getData();
             $passwordAgain = $passwordAgainField->getData();
             if ($passwordAgain != $password) {
                 $valid = false;
                 $passwordAgainField->setErrorMessage($this->__('The value entered does not match the password entered in the password field.'));
             }
         }
     }
     $emailField = $this->getField('email');
     if (!$emailField->hasErrorMessage()) {
         $emailAgainField = $this->getField('emailagain');
         $email = $emailField->getData();
         $emailAgain = $emailAgainField->getData();
         if ($email != $emailAgain) {
             $valid = false;
             $emailAgainField->setErrorMessage($this->__('The value entered does not match the e-mail address entered in the e-mail address field.'));
         }
     }
     return $valid;
 }
Example #2
0
 /**
  * Constructs the validator, initializing the filter.
  *
  * @param ContainerInterface $serviceManager The current service manager instance.
  * @param const $filter The ID of the filter to apply.
  * @param const|array $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it.
  * @param string $errorMessage The error message to return if the data does not match the expression.
  *
  * @throws \InvalidArgumentException Thrown if the filter is not valid.
  */
 public function __construct(ContainerInterface $serviceManager, $filter = FILTER_DEFAULT, $options = null, $allow_empty_value = false, $errorMessage = null)
 {
     parent::__construct($serviceManager, $errorMessage);
     if (!isset($filter) || !is_int($filter) || empty($filter)) {
         throw new \InvalidArgumentException($this->__('Error! An invalid filter was received.'));
     }
     $this->filter = $filter;
     $this->options = $options;
     $this->allow_empty_value = (bool) $allow_empty_value;
 }