Form Multi - Values blank?
Any reason this shouldn't work within a simple module?
function form_fields($values = array(), $related_fields = array()) {
$yearsValue = explode(",",$values['years']);
$fields = parent::form_fields($values, $related_fields);
$years = array(2008 => 2008, 2009 => 2009, 2010 => 2010, 2011 => 2011, 2012 => 2012, 2013 => 2013);
$fields['years'] = array('type' => 'multi', 'options' => $years, 'value' => $yearsValue);
return $fields;
}
function on_before_clean($values = array()){
if($values['years']) {
$values['years'] = implode(",",$values['years']);
}
return $values;
}
It's saving in the database as expected, however the value will just not work. Pretty confused!
Comments
Additionally, you could try setting the "years" field as "serialized" on your module's model which will automatically JSON encode and decode:
.... public $serialized_fields = array('years');
Also, on line one in the method, you should first check for the value of $values['years'] since it won't exist when creating a new record.