Exemple #1
0
 /**
  * Determine if the user provides valid values for all fields.
  *
  * @return  boolean
  */
 public function validate()
 {
     $rules = $this->rules();
     $values = $this->data;
     $validator = new Validator($values, $rules);
     if ($validator->fails()) {
         $this->messages->merge($validator->errors());
         return false;
     }
     return true;
 }
Exemple #2
0
 /**
  * Perform validation on the model instance.
  *
  * @param   array   $rules     Validation rules to apply.
  * @param   array   $messages  Validation errors to display.
  *
  * @return  boolean
  */
 public function validate(array $rules = array(), array $messages = array())
 {
     // Use the rules applied statically to the model as fallback
     if (empty($rules)) {
         $rules = static::$rules;
     }
     // Nothing to validate, return early
     if (empty($rules)) {
         return true;
     }
     // Use the messages applied statically to the model as fallback
     if (empty($messages)) {
         $messages = static::$messages;
     }
     // Perform model validation
     $validator = new Validator($this->data(), $rules, $messages);
     if ($validator->fails()) {
         $this->errors()->merge($validator->errors());
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * Run the wizard dialog.
  *
  * @param   integer  $index
  * @return  string
  */
 public function launch($index = 0)
 {
     // Retrieve active view
     if (!($view = $this->nth($index))) {
         return false;
     }
     // Trigger submit event
     if (get('token') && csfr(get('token'))) {
         $form = r::data();
         $validator = new Validator($form, $view->rules());
         $valid = $validator->passes();
         // Goto next wizard step or display validation errors
         if ($valid && $view->trigger('submit', compact('form'))) {
             $next = $view->index() + 1;
             redirect::to($this->url($next));
         } else {
             if (!$valid) {
                 $view->errors($validator->errors());
             }
         }
     }
     // Generate view and return the contents
     return $this->with(array('url' => $this->url(), 'content' => $view->content()));
 }