Mitchell Steinberg wrote on Tuesday 24th of May 2011:Just thought I'd mention that repopulating checkboxes and radio buttons is working but only in relatively new builds, so you should download the latest "develop" core code.
Controller_Admin extends Controller { public function action_add_edit_admin($user_id = null) { ... $view = View::factor('admin/view_admin_add_edit'); $form = Fieldset::factory('form_admin')->add_model('Model_admin', array($user_id))->repopulate(); ... if ($form->validation()->run() == TRUE) { $success = Model_admin::register_user($form, $user_id); if ($success) { .. } else { ... } ... $view->set('user_id', $user_id); $this->template->content = $view; }
class Model_Admin extends Model_User { public static function set_form_fields(Fieldset $form, $user_id = null { if ($user_id != null) { $admin = self::get_info($user_id); if (empty($admin)) { return false; } } $form->add('first_name', 'First Name', array( 'type' => 'text', 'value' => ! empty($admin['first_name']) ? $admin['first_name'] : '', 'id' => 'first-name', 'size' => 50, ), array( array('required'), array('trim'), array('max_length', 50), ) ); $auth_groups = self::get_auth_groups(); // Generates something like: $auth_groups = array('1' => 'User', '10' => Administrator'); $form->add('group_id', 'User Type', array( 'type' => 'radio', 'options' => $auth_groups, 'id' => 'group-id', 'value' => ! empty($admin['group_id']) ? $admin['group_id'] : '', ), array( ) ); $form->add('form_cancel', null, array( 'type' => 'submit', 'value' => 'Cancel' ) ); $form->add('submit', null, array( 'type' => 'submit', 'value' => 'Submit' ) ); } }
... echo $form->show_errors(); if (empty($user_id)) echo '<h1>Create Administrator</h1>'; else echo '<h1>Edit Administrator</h1>'; echo $form->form()->open(); foreach ($form->field() as $index => $row) { echo $row; } echo $form->form()->close();
Mitchell Steinberg wrote on Wednesday 25th of May 2011:@leo-nard: That would be great if the form printing for checkboxes and radio buttons could be fixed. Thanks.
'multi_field_template' => "\t\t\t{label}\n {fields}\t\t\t{label}{required} {field}{fields}",
'multi_field_template' => "\t\t\t{label}\n {fields}\t\t\t{field}{label}{required} {fields}",
It looks like you're new here. If you want to get involved, click one of these buttons!