Without using callback_edit_field, when I read (view) the data, the page displays as shown in first attached file img1.png (with no empty text boxes at the end)...
Now I'm trying to hide password fields on read page and also want to make those fields empty on edit page, with following lines of code:
$crud->callback_edit_field("Password",array($this,"set_password_input_to_empty")); $crud->callback_edit_field("ConfPassword",array($this,"set_confpassword_input_to_empty")); if ($crud->getState() == 'read') { $crud->field_type('Password', 'hidden'); $crud->field_type('ConfPassword', 'hidden'); }
with this code, when I try to read (view) data, it's displaying empty password fields on that page as shown in second attached image (img2.png)...
The full code is as below:
function view_user(){ $this->check_logged_in(); $crud = new grocery_CRUD(); /*set theme and table*/ $crud->set_table('user'); $crud->set_subject('User'); /*column in displayed table and fields to view/add/edit */ $crud->columns('FirstName','LastName','Gender','Username'); $crud->fields('FirstName','LastName','Description','Gender','Email','Address','Username','Password','ConfPassword'); $crud->display_as('FirstName','First Name'); $crud->display_as('LastName','Surname'); $crud->display_as('ConfPassword','Confirm Password'); $crud->field_type('Description','text'); $crud->field_type('Gender', 'enum',array('Male','Female')); $crud->field_type("Address", "text"); $crud->field_type("Password", "password"); $crud->field_type("ConfPassword", "password"); /*required field in add/edit*/ $crud->required_fields('FirstName','LastName','Gender','Email','Username','Password','ConfPassword'); $crud->unique_fields('Username','Email'); $crud->callback_edit_field("Password",array($this,"set_password_input_to_empty")); $crud->callback_edit_field("ConfPassword",array($this,"set_confpassword_input_to_empty")); $crud->callback_before_insert(array($this,'unset_verification')); $crud->callback_before_update(array($this,'unset_verification')); /*form validation rules*/ $crud->set_rules("Password","Password","matches[ConfPassword]"); if ($crud->getState() == 'read') { $crud->field_type('Password', 'hidden'); $crud->field_type('ConfPassword', 'hidden'); } $output = $crud->render(); $this->load->view('admin/view/user',$output); } function set_password_input_to_empty($post_array, $primary_key=null){ return "<input type='password' name='Password' value='' />"; } function set_confpassword_input_to_empty($post_array, $primary_key=null){ return "<input type='password' name='ConfPassword' value='' />"; } function unset_verification($post_array) { $key = config_item('encryption_key'); $post_array['Password'] = hash_hmac('md5', $post_array['Password'], $key); unset($post_array['ConfPassword']); return $post_array; }
Can anybody tell me what's the problem due to which empty password fields are being displayed on read page even though they are hidden when getState()=='read' ?