⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


callback_edit_field resulting into showing fields on read page

callback_edit_field field_type-hidden

  • Please log in to reply
1 reply to this topic

#1 Nitin Thokare

Nitin Thokare

    Member

  • Members
  • PipPip
  • 25 posts

Posted 31 May 2014 - 10:21 AM

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' ?

 

 

Attached Thumbnails

  • Img1.png
  • Img2.png


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

Posted 31 May 2014 - 07:41 PM

hi there

 

Refer to the link below .. u will get solution

http://www.grocerycr...he-read-method/







Also tagged with one or more of these keywords: callback_edit_field, field_type-hidden

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users