/**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     if (!is_null($this->maxLength) && mb_strlen($this->value) > $this->maxLength) {
         $validator->validationError($this->name, _t('TextField.VALIDATEMAXLENGTH', 'The value for {name} must not exceed {maxLength} characters in length', array('name' => $this->getName(), 'maxLength' => $this->maxLength)), "validation");
         return false;
     }
     return true;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     if (!$this->value) {
         return true;
     }
     if ($this->isNumeric()) {
         return true;
     }
     $validator->validationError($this->name, _t('NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field", array('value' => $this->value)), "validation");
     return false;
 }
 /**
  * Pass each field to be validated as a seperate argument to the constructor
  * of this object. (an array of elements are ok).
  */
 public function __construct()
 {
     $required = func_get_args();
     if (isset($required[0]) && is_array($required[0])) {
         $required = $required[0];
     }
     if (!empty($required)) {
         $this->required = ArrayLib::valuekey($required);
     } else {
         $this->required = array();
     }
     parent::__construct();
 }
예제 #4
0
 public function debug()
 {
     $result = "<h3>{$this->class}</h3><ul>";
     foreach ($this->fields as $field) {
         $result .= "<li>{$field}" . $field->debug() . "</li>";
     }
     $result .= "</ul>";
     if ($this->validator) {
         /** @skipUpgrade */
         $result .= '<h3>' . _t('Form.VALIDATOR', 'Validator') . '</h3>' . $this->validator->debug();
     }
     return $result;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     $name = $this->name;
     // if field isn't visible, don't validate
     if (!$this->isSaveable()) {
         return true;
     }
     $this->passwordField->setValue($this->value);
     $this->confirmPasswordfield->setValue($this->confirmValue);
     $value = $this->passwordField->Value();
     // both password-fields should be the same
     if ($value != $this->confirmPasswordfield->Value()) {
         $validator->validationError($name, _t('Form.VALIDATIONPASSWORDSDONTMATCH', "Passwords don't match"), "validation");
         return false;
     }
     if (!$this->canBeEmpty) {
         // both password-fields shouldn't be empty
         if (!$value || !$this->confirmPasswordfield->Value()) {
             $validator->validationError($name, _t('Form.VALIDATIONPASSWORDSNOTEMPTY', "Passwords can't be empty"), "validation");
             return false;
         }
     }
     // lengths
     if ($this->minLength || $this->maxLength) {
         $errorMsg = null;
         $limit = null;
         if ($this->minLength && $this->maxLength) {
             $limit = "{{$this->minLength},{$this->maxLength}}";
             $errorMsg = _t('ConfirmedPasswordField.BETWEEN', 'Passwords must be {min} to {max} characters long.', array('min' => $this->minLength, 'max' => $this->maxLength));
         } elseif ($this->minLength) {
             $limit = "{{$this->minLength}}.*";
             $errorMsg = _t('ConfirmedPasswordField.ATLEAST', 'Passwords must be at least {min} characters long.', array('min' => $this->minLength));
         } elseif ($this->maxLength) {
             $limit = "{0,{$this->maxLength}}";
             $errorMsg = _t('ConfirmedPasswordField.MAXIMUM', 'Passwords must be at most {max} characters long.', array('max' => $this->maxLength));
         }
         $limitRegex = '/^.' . $limit . '$/';
         if (!empty($value) && !preg_match($limitRegex, $value)) {
             $validator->validationError($name, $errorMsg, "validation");
         }
     }
     if ($this->requireStrongPassword) {
         if (!preg_match('/^(([a-zA-Z]+\\d+)|(\\d+[a-zA-Z]+))[a-zA-Z0-9]*$/', $value)) {
             $validator->validationError($name, _t('Form.VALIDATIONSTRONGPASSWORD', "Passwords must have at least one digit and one alphanumeric character"), "validation");
             return false;
         }
     }
     // Check if current password is valid
     if (!empty($value) && $this->getRequireExistingPassword()) {
         if (!$this->currentPasswordValue) {
             $validator->validationError($name, _t('ConfirmedPasswordField.CURRENT_PASSWORD_MISSING', "You must enter your current password."), "validation");
             return false;
         }
         // Check this password is valid for the current user
         $member = Member::currentUser();
         if (!$member) {
             $validator->validationError($name, _t('ConfirmedPasswordField.LOGGED_IN_ERROR', "You must be logged in to change your password."), "validation");
             return false;
         }
         // With a valid user and password, check the password is correct
         $checkResult = $member->checkPassword($this->currentPasswordValue);
         if (!$checkResult->valid()) {
             $validator->validationError($name, _t('ConfirmedPasswordField.CURRENT_PASSWORD_ERROR', "The current password you have entered is not correct."), "validation");
             return false;
         }
     }
     return true;
 }
 /**
  * Validate this field
  *
  * @todo Very basic validation at the moment
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     $valid = preg_match('/^[0-9\\+\\-\\(\\)\\s\\#]*$/', $this->joinPhoneNumber($this->value));
     if (!$valid) {
         $validator->validationError($this->name, _t('PhoneNumberField.VALIDATION', "Please enter a valid phone number"), "validation");
         return false;
     }
     return true;
 }
 /**
  * Validation method for this field, called when the entire form is validated
  *
  * @param Validator $validator
  * @return boolean
  */
 public function validate($validator)
 {
     $name = $this->getName();
     $files = $this->getItems();
     // If there are no files then quit
     if ($files->count() == 0) {
         return true;
     }
     // Check max number of files
     $maxFiles = $this->getAllowedMaxFileNumber();
     if ($maxFiles && $files->count() > $maxFiles) {
         $validator->validationError($name, _t('UploadField.MAXNUMBEROFFILES', 'Max number of {count} file(s) exceeded.', array('count' => $maxFiles)), "validation");
         return false;
     }
     // Revalidate each file against nested validator
     $this->upload->clearErrors();
     foreach ($files as $file) {
         // Generate $_FILES style file attribute array for upload validator
         $tmpFile = array('name' => $file->Name, 'type' => null, 'size' => $file->AbsoluteSize, 'tmp_name' => null, 'error' => UPLOAD_ERR_OK);
         $this->upload->validate($tmpFile);
     }
     // Check all errors
     if ($errors = $this->upload->getErrors()) {
         foreach ($errors as $error) {
             $validator->validationError($name, $error, "validation");
         }
         return false;
     }
     return true;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     $values = $this->getValueArray();
     $validValues = $this->getValidValues();
     // Filter out selected values not in the data source
     $self = $this;
     $invalidValues = array_filter($values, function ($userValue) use($self, $validValues) {
         foreach ($validValues as $formValue) {
             if ($self->isSelectedValue($formValue, $userValue)) {
                 return false;
             }
         }
         return true;
     });
     if (empty($invalidValues)) {
         return true;
     }
     // List invalid items
     $validator->validationError($this->getName(), _t('MultiSelectField.SOURCE_VALIDATION', "Please select values within the list provided. Invalid option(s) {value} given", array('value' => implode(',', $invalidValues))), "validation");
     return false;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     $value = $this->Value();
     if (!$value) {
         return true;
         // no custom value, don't validate
     }
     // Check that the current date with the date format is valid or not
     require_once 'Zend/Date.php';
     $date = Zend_Date::now()->toString($value);
     $valid = Zend_Date::isDate($date, $value);
     if ($valid) {
         return true;
     }
     // Fail
     $validator->validationError($this->getName(), _t('MemberDatetimeOptionsetField.DATEFORMATBAD', "Date format is invalid"), "validation");
     return false;
 }
 /**
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     // Don't validate empty fields
     if (empty($this->value)) {
         return true;
     }
     // date format
     if ($this->getConfig('dmyfields')) {
         $valid = !$this->value || $this->validateArrayValue($this->value);
     } else {
         $valid = Zend_Date::isDate($this->value, $this->getConfig('dateformat'), $this->locale);
     }
     if (!$valid) {
         $validator->validationError($this->name, _t('DateField.VALIDDATEFORMAT2', "Please enter a valid date format ({format})", array('format' => $this->getConfig('dateformat'))), "validation");
         return false;
     }
     // min/max - Assumes that the date value was valid in the first place
     if ($min = $this->getConfig('min')) {
         // ISO or strtotime()
         if (Zend_Date::isDate($min, $this->getConfig('datavalueformat'))) {
             $minDate = new Zend_Date($min, $this->getConfig('datavalueformat'));
         } else {
             $minDate = new Zend_Date(strftime('%Y-%m-%d', strtotime($min)), $this->getConfig('datavalueformat'));
         }
         if (!$this->valueObj || !$this->valueObj->isLater($minDate) && !$this->valueObj->equals($minDate)) {
             $validator->validationError($this->name, _t('DateField.VALIDDATEMINDATE', "Your date has to be newer or matching the minimum allowed date ({date})", array('date' => $minDate->toString($this->getConfig('dateformat')))), "validation");
             return false;
         }
     }
     if ($max = $this->getConfig('max')) {
         // ISO or strtotime()
         if (Zend_Date::isDate($min, $this->getConfig('datavalueformat'))) {
             $maxDate = new Zend_Date($max, $this->getConfig('datavalueformat'));
         } else {
             $maxDate = new Zend_Date(strftime('%Y-%m-%d', strtotime($max)), $this->getConfig('datavalueformat'));
         }
         if (!$this->valueObj || !$this->valueObj->isEarlier($maxDate) && !$this->valueObj->equals($maxDate)) {
             $validator->validationError($this->name, _t('DateField.VALIDDATEMAXDATE', "Your date has to be older or matching the maximum allowed date ({date})", array('date' => $maxDate->toString($this->getConfig('dateformat')))), "validation");
             return false;
         }
     }
     return true;
 }
 /**
  * Validation method for this field, called when the entire form is validated
  *
  * @param Validator $validator
  * @return boolean
  */
 public function validate($validator)
 {
     $name = $this->getName();
     $value = $this->Value();
     // If there is no file then quit
     if (!$value) {
         return true;
     }
     // Revalidate each file against nested validator
     $this->getUpload()->clearErrors();
     // Generate $_FILES style file attribute array for upload validator
     $store = $this->getAssetStore();
     $mime = $store->getMimeType($value['Filename'], $value['Hash'], $value['Variant']);
     $metadata = $store->getMetadata($value['Filename'], $value['Hash'], $value['Variant']);
     $tmpFile = array('name' => $value['Filename'], 'type' => $mime, 'size' => isset($metadata['size']) ? $metadata['size'] : 0, 'tmp_name' => null, 'error' => UPLOAD_ERR_OK);
     $this->getUpload()->validate($tmpFile);
     // Check all errors
     if ($errors = $this->getUpload()->getErrors()) {
         foreach ($errors as $error) {
             $validator->validationError($name, $error, "validation");
         }
         return false;
     }
     return true;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     // Check if valid value is given
     $selected = $this->Value();
     if (strlen($selected)) {
         // Use selection rules to check which are valid
         foreach ($this->getValidValues() as $formValue) {
             if ($this->isSelectedValue($formValue, $selected)) {
                 return true;
             }
         }
     } else {
         if ($this->getHasEmptyDefault()) {
             // Check empty value
             return true;
         }
         $selected = '(none)';
     }
     // Fail
     $validator->validationError($this->name, _t('DropdownField.SOURCE_VALIDATION', "Please select a value within the list provided. {value} is not a valid option", array('value' => $selected)), "validation");
     return false;
 }
 /**
  * Validate this field
  *
  * @param Validator $validator
  * @return bool
  */
 public function validate($validator)
 {
     // Don't validate empty fields
     if (empty($this->value)) {
         return true;
     }
     if (!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) {
         $validator->validationError($this->name, _t('TimeField.VALIDATEFORMAT', "Please enter a valid time format ({format})", array('format' => $this->getConfig('timeformat'))), "validation");
         return false;
     }
     return true;
 }