⚠ 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 is an archived forum. ⚠

  •     

profile picture

callback_add_field not working?



ceroberoz
  • profile picture
  • Member

Posted 17 February 2014 - 11:44 AM

Hi, I tried to add email as readonly field / readonly in grocery crud

in the add form, the callback is works fine

image.png

but when I click save, the callback is ignored

image.png

 

this is my code, is I am missing something? thanks

// the function
function tema(){
        $crud = new grocery_CRUD();

        $crud->set_table('design_theme')
             ->add_fields('theme','email')
             ->edit_fields('theme','email','status')
             ->field_type('email','readonly')
             ->display_as('theme','Tema')
             ->display_as('theme_date','Tanggal Tema')
             ->callback_add_field('email',array($this,'mail_callbacks'));

        $output = $crud->render();
        $this->kekgwpeduliaja($output);
    }
// the callback
function mail_callbacks(){
        $user = $this->ion_auth->user()->row();
        $mail = $user->email;
        return '<input type="text" id="email" name="email" value="'.$mail.'" disabled />';
    }

Amit Shah
  • profile picture
  • Member

Posted 17 February 2014 - 13:37 PM

What do u mean by the term callback is ignored. The callback is designed to work only when it is being displayed. And when a type is read only.. i believe GC library ignores the value of the field that needs to be saved. U have 2 options in this scenario...

make a extra field - email ... set its in case of state -> Add - make the type of the field read-only ... (of the extra field) and set the email field to be hidden with the value set inside it. This is fine 2 go with but then has a catch - it can be tempered. There is another way round -

set the field type - readonly - it will be shown as string rather then box ... and not considered for update. This can be non existant field...

and set the email to be hidden with no value...

and make a callback before insert and set the value of email there ... this will make system full proof - disallow user from making any kind of alterations to the system.