public function action_edit($id=0) { // get the current data for the id $model = \Content\Model_page::find($id); if(!$model) $model = new \Content\Model_page(); // validate the model if($model->validate()) // I've extended the ORM model to get the Post data and validate it { $model->module = 'pages'; $model->save(); \Response::redirect('your_action_list'); } // create the form passing the action as parameter. Second parameter is the asset group for the associated javascript $form = new \Forms\Form("admin/content/pages/edit/$id", 'backend'); // information on validation rules, label and input info can be stored in the model $_properties variable $form->add_model('id',$model); // wich is a shorcut for $form->add('hidden', 'input-name', 'input-value'); $f = $form->add_model('title',$model); // a text field // wich is a shorcut for $f = $form->add('text', 'input-name', 'input-value', 'input-label'); $f ->rules('required'); // if not setted in the model. // a tiny editor field, with few edit buttons $f = $form->add_model('preview', $model, 'main_left'); $f->config(array('mode'=>'simple')); // a tiny editor field, with all edit options $f = $form->add_model('body', $model, 'main_left'); $f->config(array('mode'=>'advanced')); $data = array( 'form'=> $form, 'cancel'=>'your_list_action', ); $this->template->content = \View::factory('admin/edit', $data, false); }
$form->render() // this renders the complete form // or if you wish to render the fields individually $form->open() $form->title->render() $form->preview->render() // etc $form->close();
Can you expand your thoughts on this a little further? Thanks for your answer.I'm still thinking about doing something clever with Form and Fieldset objects in the Viewmodel, so they're easy to use for an UI designer (as in full markup flexibility)...
{fuel:form name="test" action="/here/there"} <!-- html here --> {/fuel:form}
It looks like you're new here. If you want to get involved, click one of these buttons!