In a model: How do I display in the create form, only the fields that I select from the table?

edited May 2012 in Modules
Im my model I have these functions:

function list_items($limit = NULL, $offset = NULL, $col = 'username', $order = 'asc')
{
$this->db->select('id, username, password, email');
$data = parent::list_items($limit, $offset, $col, $order);
return $data;
}

function form_fields($values = array())
{
$fields = parent::form_fields();

$fields['email'] = array('label' => 'Email', 'required' => TRUE);
$fields['password'] = array('type' => 'password', 'label' => 'Password', 'required' => TRUE);
return $fields;
}

When I go to the dashborad to create a teacher, I see a form with all the fields that I have in the users table.

I want to see only the fields that I select from the table, what am I doing wrong?

Comments

  • edited 12:18PM
    Is that the way to do it?

    $fields['banned']['type'] = 'hidden';

    And do that for each field that I don't want to display on the form?
  • edited 12:18PM
    The list_items() function is for the list page that you initially see when clicking on the module, form_fields() controls the create /edit form (as you will know by now).

    So yes you would need to hide fields individually, although you could create a loop to do the heavy lifting if there are more than you want to show I suppose.
Sign In or Register to comment.