Change field value display in Module form (form_fields)

edited July 2013 in Modules
What I'm trying to do:
I have a field in my DB 'last_login' which is an int(11) field, which holds a epoch_timestamp.

In the Module record edit display I want to show this field, but not allow editing. But I'd like to display a friendly date, not the epoch timestamp.

What I've done:

[code]
function form_fields($values)
{
$fields = parent::form_fields($values);
$values['last_login'] = date('m/d/Y', $values['last_login']);
$fields['last_login'] = array('value' => $values['last_login'],'displayonly' => true);

return $fields;
}
[/code]

I would expect to see in the edit form:

Last Login: 7/13/2013

but I'm still seeing the timestamp, not the friendly date.

Is it possible to set a field value in the form_fields method?

(using 1.0 branch, last merge from github: SHA 9dff5bd)

Comments

  • edited 5:37AM
    This is because the data being displayed is pulled using the find_all_array method by default and will overwrite any value parameters if they are set. Value parameters in this context only work when you are initially creating a record. After that, they are overwritten by the values in the database. To get around this, you can setup your own "edit_method" which essentially does the find_all_array and converts the epoch timestamp. Or you can overwrite the find_all_array method on your model. If you create your own, you'll need to set the "edit_method" parameter in your MY_fuel_modules.php file.
Sign In or Register to comment.