Example #1
0
 /**
  * Create a new instance of the form data container, intializing the fields and validators.
  *
  * @param string                 $formId                       The id value to use for the form.
  * @param \Zikula_ServiceManager $serviceManager               The current service manager instance.
  * @param bool                   $passwordReminderNotMandatory Set it to true to remove the mandatory validation of the password reminder. Overwrites modvar.
  */
 public function __construct($formId, \Zikula_ServiceManager $serviceManager = null, $passwordReminderNotMandatory = false)
 {
     parent::__construct($formId, $serviceManager);
     $this->addField(new Field($this, 'uname', '', '', $this->serviceManager))->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')))->addValidator(new Validator\StringMinimumLength($this->serviceManager, 1, $this->__('A user name is required, and cannot be left blank.')))->addValidator(new Validator\StringRegularExpression($this->serviceManager, '/^' . UsersConstant::UNAME_VALIDATION_PATTERN . '$/uD', $this->__('The value does not appear to be a valid user name. A valid user name consists of lowercase letters, numbers, underscores, periods or dashes.')))->addValidator(new Validator\StringLowerCase($this->serviceManager, $this->__('The value does not appear to be a valid user name. A valid user name consists of lowercase letters, numbers, underscores, periods or dashes.')));
     $passwordMinimumLength = (int) $this->getVar(UsersConstant::MODVAR_PASSWORD_MINIMUM_LENGTH, UsersConstant::DEFAULT_PASSWORD_MINIMUM_LENGTH);
     $this->addField(new Field($this, 'pass', '', '', $this->serviceManager))->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')))->addValidator(new Validator\StringMinimumLength($this->serviceManager, $passwordMinimumLength, $this->__f('Passwords must be at least %1$d characters in length.', array($passwordMinimumLength))));
     $this->addField(new Field($this, 'passagain', '', '', $this->serviceManager))->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')));
     if ((bool) $this->getVar(UsersConstant::MODVAR_PASSWORD_REMINDER_ENABLED, UsersConstant::DEFAULT_PASSWORD_REMINDER_ENABLED)) {
         $passReminderField = new Field($this, 'passreminder', false, false, $this->serviceManager);
         $passReminderField->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')));
         if ((bool) $this->getVar(UsersConstant::MODVAR_PASSWORD_REMINDER_MANDATORY, UsersConstant::DEFAULT_PASSWORD_REMINDER_MANDATORY) && !$passwordReminderNotMandatory) {
             $passReminderField->addValidator(new Validator\StringMinimumLength($this->serviceManager, 1, $this->__('A password reminder is required, and cannot be left blank.')));
         }
         $this->addField($passReminderField);
     }
     $this->addField(new Field($this, 'email', '', '', $this->serviceManager))->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')))->addValidator(new Validator\StringMinimumLength($this->serviceManager, 1, $this->__('An e-mail address is required, and cannot be left blank.')))->addValidator(new Validator\FilterVar($this->serviceManager, FILTER_VALIDATE_EMAIL, null, false, $this->__('The value entered does not appear to be a valid email address.')));
     $this->addField(new Field($this, 'emailagain', '', '', $this->serviceManager))->setNullAllowed(false)->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')));
     $antispamQuestion = $this->getVar(UsersConstant::MODVAR_REGISTRATION_ANTISPAM_QUESTION, '');
     $this->addField(new Field($this, 'antispamanswer', '', '', $this->serviceManager))->setNullAllowed(empty($antispamQuestion))->addValidator(new Validator\StringType($this->serviceManager, $this->__('The value must be a string.')));
 }