Hi,
I've have a little bit of an issue.
In one of the controllers ("pages") of my application, I want a logged in user to add an entry.
On the index of the controller, ie, the list of all posts, the users firstname and lastname should be seen.
Easy-peasy, right;
$crud->set_relation('user_id','users','{first_name} {last_name}');
But - I want to disable the input field on add and edit, because I want the user_id to be set automaticly (from a session variable).
This doesn't work, so I googled the problem and found a post somewhere on this forum saying that a field cannot be invisible (or for that matter disabled) when it has a relation.
I get the point that when you use a relation in the list, the same relation should be used to get a dropdown of possible values. But in this case, it's not needed. Or really, it's not even smart to have it, since each post should have the correct creator.
Is there a way to fix this?
I've done this to get it working:
public function _callback_set_username($value,$row) { return "<input id='field-user_id' name='user_id' type='text' value='".$_SESSION['first_name']." ".$_SESSION['last_name']."' readonly='readonly' disabled='disabled' />"; } $crud->callback_field('user_id',array($this,'_callback_set_username'));
And a in another callback, used on callback_before_insert/update, the sessions user_id is set to the post data user_id.
It works, but it seems like a bit of extra coding for no reason.
Regards
Jonathan