<h2 class="first">New Article</h2> <?php echo isset($errors) ? $errors : false; ?> <?php echo Form::open(); ?> <p> <?php echo Form::label('Name', 'name'); ?> <?php echo Form::input('name', Input::post('name', isset($article) ? $article->name : '')); ?> </p> <p> <?php echo Form::label('Count', 'count'); ?> <?php echo Form::input('count', Input::post('count', isset($article) ? $article->count : '')); ?> </p> <div class="actions"><?php echo Form::submit(); ?></div> <?php echo Form::close(); ?>My CONTROLLER function (generated with scaffolding / with validation):
public function action_create($id = null) { if (Input::method() == 'POST') { $val = Validation::factory(); $val->add_field('name', 'Name', 'required'); if($val->run()) { $article = Model_Article::factory(array( 'name' => Input::post('name'), 'count' => Input::post('count'), )); if ($article and $article->save()) { Session::set_flash('notice', 'Added article #' . $article->id . '.'); Response::redirect('articles'); } else { Session::set_flash('notice', 'Could not save article.'); } } else { $this->template->errors = $val->errors(); } } $this->template->title = "Articles"; $this->template->content = View::factory('articles/create'); }
else { $data['errors'] = $val->show_errors(); } $this->template->title = "Articles"; $this->template->content = View::factory('articles/create', $data, false);
It looks like you're new here. If you want to get involved, click one of these buttons!