/**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     //ClearErrors?
     if ($clearErrors) {
         $this->clearErrors();
     }
     //Any recipients specified?
     if ($this->sendto_usergroups == false && $this->sendto_users == false) {
         $this->addError('sendto', Craft::t('No recipients specified'));
     }
     //UserGroup recipients
     if ($this->sendto_usergroups) {
         if (!$this->usergroups) {
             $this->addError('usergroups', Craft::t('No usergroups specified'));
         } elseif (array_filter($this->usergroups, 'is_int') === $this->usergroups) {
             $this->addError('usergroups', Craft::t('Invalid usergroups specified'));
         }
     }
     //User recipients
     if ($this->sendto_users) {
         if (!$this->users) {
             $this->addError('users', Craft::t('No users specified'));
         } elseif (array_filter($this->users, 'is_int') === $this->users) {
             $this->addError('users', Craft::t('Invalid users specified'));
         }
     }
     //Return
     return parent::validate($attributes, false);
 }
 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if (is_array($this->types)) {
         if (in_array('entry', $this->types) && $this->entrySources == '') {
             $this->addError('entrySources', Craft::t('Please select at least 1 entry source.'));
         }
         if (in_array('asset', $this->types) && $this->assetSources == '') {
             $this->addError('assetSources', Craft::t('Please select at least 1 asset source.'));
         }
         if (in_array('category', $this->types) && $this->categorySources == '') {
             $this->addError('categorySources', Craft::t('Please select at least 1 category source.'));
         }
         if (in_array('product', $this->types) && $this->productSources == '') {
             $this->addError('productSources', Craft::t('Please select at least 1 product source.'));
         }
         // Handle third party element errors
         $thirdPartyElementTypes = craft()->fruitLinkIt->getThirdPartyElementTypes();
         foreach ($thirdPartyElementTypes as $elementTypeHandle => $elementTypeConfig) {
             if (in_array($elementTypeHandle, $this->types) && $this[$elementTypeHandle . 'Sources'] == '') {
                 $this->addError($elementTypeHandle . 'Sources', Craft::t('Please select at least 1 ' . strtolower($elementTypeConfig['name']) . ' source.'));
             }
         }
     } else {
         $this->addError('types', Craft::t('Please select at least 1 link type.'));
     }
     return !$this->hasErrors();
 }
 /**
  * Validates the custom fields.
  *
  * @param array|null $attributes
  * @param bool       $clearErrors
  *
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     $validates = parent::validate($attributes, $clearErrors);
     foreach (craft()->fields->getAllFields() as $field) {
         $handle = $field->handle;
         if (is_array($attributes) && !in_array($handle, $attributes)) {
             continue;
         }
         $value = $this->getAttribute($handle);
         // Don't worry about blank values. Those will already be caught by required field validation.
         if ($value) {
             $fieldType = $field->getFieldType();
             if ($fieldType) {
                 $errors = $fieldType->validate($value);
                 if ($errors !== true) {
                     if (is_string($errors)) {
                         $this->addError($handle, $errors);
                     } else {
                         if (is_array($errors)) {
                             foreach ($errors as $error) {
                                 $this->addError($handle, $error);
                             }
                         }
                     }
                     $validates = false;
                 }
             }
         }
     }
     return $validates;
 }
Example #4
0
 /**
  * Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get
  * logged to the `craft/storage/runtime/logs` folder with a level of LogLevel::Warning.
  *
  * In addition, we check that the username does not have any whitespace in it.
  *
  * @param null $attributes
  * @param bool $clearErrors
  *
  * @return bool|null
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     // Don't allow whitespace in the username.
     if (preg_match('/\\s+/', $this->username)) {
         $this->addError('username', Craft::t('Spaces are not allowed in the username.'));
     }
     return parent::validate($attributes, false);
 }
 /**
  * Add custom validation rules to routine.
  *
  * @param Array $attributes
  * @param Bool $clearErrors
  * @return Bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     if ($clearErrors) {
         $this->clearErrors();
     }
     $this->validateCachePathAndUrl();
     return parent::validate($attributes, false);
 }
Example #6
0
 /**
  * Returns the translated definition for the word hatred
  *
  * {Injects a static method dependency for Craft::t}
  *
  * @param	string	$translator	The name of the static class that defines t()
  *
  * @return	string
  */
 public function getTranslatedDefinition(BaseModel $model)
 {
     if ($model->validate()) {
         // Static method dependencies are just not elegant to work with
         // We can use $model->property but using $model->getAttribute('property') make this method more testable
         return call_user_func_array($this->translator . '::t', array($model->getAttribute('definition')));
     }
     return false;
 }
 public function validate($attributes = null, $clearErrors = true)
 {
     // Enforce $clearErrors without copying code if we don't have to
     $validates = parent::validate($attributes, $clearErrors);
     if (!craft()->superTable->validateFieldSettings($this)) {
         $validates = false;
     }
     return $validates;
 }
Example #8
0
 /**
  * Throws exceptions for validation errors when in devMode.
  *
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     $validate = parent::validate($attributes, $clearErrors);
     if (!$validate && craft()->config->get('devMode')) {
         foreach ($this->getAllErrors() as $attribute => $error) {
             throw new Exception(Craft::t($error));
         }
     }
     return $validate;
 }
Example #9
0
 public function validate($model = null)
 {
     if (parent::validate()) {
         if (is_object(static::buscar($this->formulario, $this->campo)) && !isset($this->id)) {
             $this->errors->add('formulario', 'El formulario debe ser unico');
         }
         return !$this->hasErrors();
     }
     return false;
 }
 public function validate($attributes = null, $clearErrors = true)
 {
     $arr = explode("/", $this->birth);
     if (count($arr) != 3) {
         $this->addError('birth', Craft::t('Incorrect date format, please use DD/MM/YY date format'));
     } else {
         if (strlen($arr[0]) != 2 || $arr[0] < 1 || $arr[0] > 31 || strlen($arr[1]) != 2 || $arr[1] < 1 || $arr[1] > 12 || strlen($arr[2]) != 2 || $arr[2] < 96 && $arr[2] > 14 || $arr[2] < 0) {
             $this->addError('birth', Craft::t('Incorrect date format, please use DD/MM/YY date format'));
         }
     }
     return parent::validate($attributes, false);
 }
 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if ($this->yearRangeStart) {
         if (!is_numeric($this->yearRangeStart) && strtotime($this->yearRangeStart) === false) {
             $this->addError('yearRangeStart', Craft::t('Not a valid value, use a full year notation or a strtotime() value.'));
         }
     }
     if ($this->yearRangeEnd) {
         if (!is_numeric($this->yearRangeEnd) && strtotime($this->yearRangeEnd) === false) {
             $this->addError('yearRangeEnd', Craft::t('Not a valid value, use a full year notation or a strtotime() value.'));
         }
     }
     return !$this->hasErrors();
 }
 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     //ClearErrors?
     if ($clearErrors) {
         $this->clearErrors();
     }
     //Mail RegEx
     $regex = '/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i';
     //Any Recipient specified?
     if (empty($this->recipients)) {
         $this->addError('recipients', Craft::t('No recipients specified'));
     } else {
         //Check each array
         foreach ($this->recipients as $array) {
             //To (required)
             /*$to_emails = preg_split('[,]', $array['to']);
             
             				foreach($to_emails as $mail) {
             					if (preg_match( $regex, trim($mail) ) == 0) {
             						$this->addError('to', trim($mail) . Craft::t(' is not a valid email'));
             					}
             				}*/
             if (preg_match($regex, $array['to']) == 0) {
                 $this->addError('to', $array['to'] . Craft::t(' is not a valid email'));
             }
             //Currently only one 'to' address is allowed.
             //CC (optional)
             if (!empty($array['cc'])) {
                 $cc_emails = preg_split('[,]', $array['cc']);
                 foreach ($cc_emails as $mail) {
                     if (preg_match($regex, trim($mail)) == 0) {
                         $this->addError('cc', trim($mail) . Craft::t(' is not a valid email'));
                     }
                 }
             }
             //BCC (optional)
             if (!empty($array['bcc'])) {
                 $bcc_emails = preg_split('[,]', $array['bcc']);
                 foreach ($bcc_emails as $mail) {
                     if (preg_match($regex, trim($mail)) == 0) {
                         $this->addError('bcc', trim($mail) . Craft::t(' is not a valid email'));
                     }
                 }
             }
         }
     }
     return parent::validate($attributes, false);
 }
 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     if (is_array($this->types)) {
         if (in_array('entry', $this->types) && $this->entrySources == '') {
             $this->addError('entrySources', Craft::t('Please select at least 1 entry source.'));
         }
         if (in_array('asset', $this->types) && $this->assetSources == '') {
             $this->addError('assetSources', Craft::t('Please select at least 1 asset source.'));
         }
         if (in_array('category', $this->types) && $this->categorySources == '') {
             $this->addError('categorySources', Craft::t('Please select at least 1 category source.'));
         }
         if (in_array('product', $this->types) && $this->productSources == '') {
             $this->addError('productSources', Craft::t('Please select at least 1 product source.'));
         }
     } else {
         $this->addError('types', Craft::t('Please select at least 1 link type.'));
     }
     return !$this->hasErrors();
 }
 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     // Don't allow whitespace in the code.
     /*  if (preg_match('/\s+/', $this->code)) {
             $this->addError('code', Craft::t('Spaces are not allowed in the coupon code.'));
         }*/
     if ($this->couponType == 'percentage' and $this->percentageOff == '') {
         $this->addError('percentageOff', Craft::t('Percentage Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '') {
         $this->addError('amountOff', Craft::t('Amount Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '') {
         $this->addError('amountOff', Craft::t('Amount Off is required'));
     }
     if ($this->couponType == 'amount' and $this->amountOff == '0') {
         $this->addError('amountOff', Craft::t('Amount Off must be more than 0'));
     }
     if ($this->duration == 'repeating' and ($this->durationInMonths == '' or $this->durationInMonths == '0')) {
         $this->addError('durationInMonths', Craft::t('Duration in Months is required if the Duration is set to \'Repeating\'. Set to \'Forever\' for no limit'));
     }
     return parent::validate($attributes, false);
 }
 /**
  * Validates all the attributes, block types and groups.
  *
  * @param array|null $attributes
  * @param bool|true $clearErrors
  * @return bool
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     return parent::validate($attributes, $clearErrors) && craft()->neo->validateFieldSettings($this);
 }
 /**
  * @param null $attributes
  * @param bool $clearErrors
  * @return bool|void
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     //ClearErrors?
     if ($clearErrors) {
         $this->clearErrors();
     }
     //Any recipients specified?
     if ($this->sendto_custom == false && $this->sendto_usergroups == false && $this->sendto_users == false) {
         $this->addError('sendto', Craft::t('No recipients specified'));
     }
     //Custom recipients
     if ($this->sendto_custom) {
         $regex = '/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i';
         //Recipients
         if (!empty($this->to)) {
             /*
             				$recipient_emails = preg_split('[,]', $this->to);
             				$i = 1;
             				
             				foreach($recipient_emails as $mail) {
             					if (preg_match( $regex, trim($mail) ) == 0) {
             						$this->addError('to', '(' .$i. ') ' . trim($mail) . Craft::t(' is not a valid email'));
             					}
             					$i++;
             				}*/
             if (preg_match($regex, $this->to) == 0) {
                 $this->addError('to', $this->to . Craft::t(' is not a valid email'));
             }
             //Currently only one 'to' address is allowed.
         } else {
             $this->addError('to', Craft::t('No recipients specified'));
         }
         //CC
         if (!empty($this->cc)) {
             $cc_emails = preg_split('[,]', $this->cc);
             $i = 1;
             foreach ($cc_emails as $mail) {
                 if (preg_match($regex, trim($mail)) == 0) {
                     $this->addError('cc', '(' . $i . ') ' . trim($mail) . Craft::t(' is not a valid email'));
                 }
                 $i++;
             }
         }
         //BCC
         if (!empty($this->bcc)) {
             $bcc_emails = preg_split('[,]', $this->bcc);
             $i = 1;
             foreach ($bcc_emails as $mail) {
                 if (preg_match($regex, trim($mail)) == 0) {
                     $this->addError('bcc', '(' . $i . ') ' . trim($mail) . Craft::t(' is not a valid email'));
                 }
                 $i++;
             }
         }
     }
     //UserGroup recipients
     if ($this->sendto_usergroups) {
         if (!$this->usergroups) {
             $this->addError('usergroups', Craft::t('No usergroups specified'));
         } elseif (array_filter($this->usergroups, 'is_int') === $this->usergroups) {
             $this->addError('usergroups', Craft::t('Invalid usergroups specified'));
         }
     }
     //User recipients
     if ($this->sendto_users) {
         if (!$this->users) {
             $this->addError('users', Craft::t('No users specified'));
         } elseif (array_filter($this->users, 'is_int') === $this->users) {
             $this->addError('users', Craft::t('Invalid users specified'));
         }
     }
     //Message (Safe-Mode)
     if (craft()->plugins->getPlugin('mailer')->getSettings()->safeMode) {
         $body = $this->htmlBody;
         //Remove "allowed" variables
         $allowed = array('/{{ user.firstName }}/i', '/{{ user.lastName }}/i', '/{{ user.email }}/i', '/{{ user.username }}/i');
         $body = preg_replace($allowed, ' ', $body);
         //Check for other Twig code
         if (preg_match_all('({{|}}|{%|%})', $body) != 0) {
             $this->addError('htmlBody', Craft::t('Please remove all {{, }}, {%, %} which are not part of a variable'));
         }
     }
     //Return
     return parent::validate($attributes, false);
 }
Example #17
0
 public function validate($datas = [])
 {
     if ($datas == null) {
         $datas = array_merge($this->_cols, get_object_vars($this));
     }
     return parent::validate($datas);
 }
Example #18
0
 public function validate($model = null)
 {
     if (parent::validate($model)) {
         if (isset($this->id)) {
             $area_anterior = Area::find($this->getOriginal('area_id'));
             //no se puede cambiar el tipo de ayuda de la solicitud
             if ($area_anterior->tipo_ayuda_id != $this->area->tipo_ayuda_id) {
                 $this->addError('area->tipo_ayuda_id', 'No se puede cambiar el tipo de ayuda de la solicitud');
                 return false;
             }
         }
         return true;
     }
     return false;
 }
 public function validate()
 {
     return parent::validate() && !User::findWithEmail($this->email);
 }
Example #20
0
 public function validate($model = null)
 {
     if (parent::validate()) {
         $proceso = $this->proceso;
         if ($proceso->ind_beneficiario && $this->beneficiario_id == "") {
             $this->addError('beneficiario_id', 'El beneficiario es necesario');
         }
         if ($proceso->ind_monto) {
             if ($this->monto == "") {
                 $this->addError('monto', 'El monto es necesario');
             }
             if ($this->monto == "") {
                 $this->addError('montoapr', 'El monto aprobado es necesario');
             }
         }
         if ($proceso->ind_cantidad && $this->cantidad == "") {
             $this->addError('cantidad', 'La cantidad es necesaria');
         }
     }
     return !$this->hasErrors();
 }
Example #21
0
 public function validate($model = null)
 {
     if (parent::validate($model)) {
         if ($this->fecha_vencimiento == "" && $this->recaudo->ind_vence) {
             $this->addError('fecha_vencimiento', "La fecha de vencimiento es necesaria");
         }
     }
     return !$this->hasErrors();
 }