Beispiel #1
0
 /**
  * Add a field to the form container.
  *
  * @param Field $field The field definition.
  *
  * @return Field A reference to the field just added, to allow for function chaining to configure the field.
  *
  * @throws \InvalidArgumentException Thrown if the field definition is not valid, a field with the specified name is already defined, or adding the field would result in a duplicate field id.
  */
 public function addField(Field $field)
 {
     if (!isset($field)) {
         throw new \InvalidArgumentException($this->__('Invalid field definition'));
     } elseif ($field->getFormContainer() !== $this) {
         throw new \InvalidArgumentException($this->__('Form container mismatch.'));
     } elseif (array_key_exists($field->fieldName, $this->formFields)) {
         throw new \InvalidArgumentException($this->__f('Field definition for the \'%1$s\' field is already defined.', array($field->fieldName)));
     } elseif (array_key_exists($field->fieldId, $this->fieldIds)) {
         throw new \InvalidArgumentException($this->__f('Field definition duplicates the field id \'%1$s\' already claimed by the field \'%2$s\'.', array($field->fieldId, $this->fieldIds[$field->fieldId])));
     }
     $this->formFields[$field->fieldName] = $field;
     $this->fieldIds[$field->fieldId] =& $this->formFields[$field->fieldName];
     return $this->formFields[$field->fieldName];
 }
Beispiel #2
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.')));
 }