/** * 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())); }