Example #1
0
 public function validate(array $attributes = null, $clearErrors = true)
 {
     if (!$this->beforeLogin() || !parent::validate($attributes, $clearErrors)) {
         return false;
     }
     $this->afterLogin();
     return true;
 }
Example #2
0
 public function validate(array $attributes = NULL, $clearErrors = true)
 {
     if (!$this->beforeSignup() || !parent::validate()) {
         return false;
     }
     $this->afterSignup();
     return true;
 }
 /**
  * @inheritdoc
  */
 public function get()
 {
     $this->model = Instance::ensure($this->model);
     if (!$this->model->isLoad()) {
         $this->validate = false;
     }
     if ($this->validate === true) {
         $this->prepareAttributes();
         if (!$this->model->validate()) {
             $this->errorsToPlaceholders($this->model);
         }
     }
     $this->config['model'] = $this->model;
     ob_start();
     $form = \rock\widgets\ActiveForm::begin($this->config);
     $output = ob_get_clean();
     $fields = [];
     $fields[] = $output;
     if (!empty($this->fields)) {
         $this->prepareFields($form, (array) $this->fields, $fields);
     }
     $fields[] = $this->prepareSubmitButton($this->submitButton);
     ob_start();
     ob_implicit_flush(false);
     \rock\widgets\ActiveForm::end();
     $output = ob_get_clean();
     $fields[] = $output;
     $result = implode("\n", $fields);
     // Inserting content into wrapper template (optional)
     if (!empty($this->wrapperTpl)) {
         $result = $this->parseWrapperTpl($result, $this->wrapperTpl);
     }
     // To placeholder
     if (!empty($this->toPlaceholder)) {
         $this->template->addPlaceholder($this->toPlaceholder, $result, true);
         $this->template->cachePlaceholders[$this->toPlaceholder] = $result;
         return '';
     }
     return $result;
 }
Example #4
0
 /**
  * Validates one or several models and returns an error message array indexed by the attribute IDs.
  * This is a helper method that simplifies the way of writing AJAX validation code.
  *
  * For example, you may use the following code in a controller action to respond
  * to an AJAX validation request:
  *
  * ```php
  * $model = new Post;
  * $model->load($_POST);
  * if (Rock::$app->request->isAjax) {
  *     Rock::$app->response->format = Response::FORMAT_JSON;
  *     return ActiveForm::validate($model);
  * }
  * // ... respond to non-AJAX request ...
  * ```
  *
  * To validate multiple models, simply pass each model as a parameter to this method, like
  * the following:
  *
  * ```php
  * ActiveForm::validate($model1, $model2, ...);
  * ```
  *
  * @param \rock\components\Model $model the model to be validated
  * @param mixed $attributes list of attributes that should be validated.
  * If this parameter is empty, it means any attribute listed in the applicable
  * validation rules should be validated.
  *
  * When this method is used to validate multiple models, this parameter will be interpreted
  * as a model.
  *
  * @return array the error message array indexed by the attribute IDs.
  */
 public static function validate($model, $attributes = null)
 {
     $result = [];
     if ($attributes instanceof Model) {
         // validating multiple models
         $models = func_get_args();
         $attributes = null;
     } else {
         $models = [$model];
     }
     /** @var \rock\components\Model $model */
     foreach ($models as $model) {
         $model->validate($attributes);
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[ActiveHtml::getInputId($model, $attribute)] = $errors;
         }
     }
     return $result;
 }