Trying to Understand Form Fields Multi Documentation
I am trying to use a MySQL "set" field type - It appears to be implemented by the Multi field as provided in the Fuel user guide by
$options = array('a' => 'option A', 'b' => 'option B', 'c' => 'option C');
$fields['multi_example'] = array('type' => 'multi', 'options' => $options, 'value' => 'a');
The code generated by this generates the needed form field, and if only one value is set, it gets into the form correctly as the initial vale.
But, if one wants to set two values (say "a" and "c") , not just one as in shown in the example, what is wanted? I tried an array, but my guess was clearly "not it".
And after submitting, some array seems to have been returned -- what is the content of that array?
I'm assuming that I will need pre- and post- processing functions to handle the translation from and to the "set" field type....
This is perhaps an example that needs to be documented as I assume most simple multi-select types of fields would be very similar.
Thanks.
Comments
$options = array('a' => 'option A', 'b' => 'option B', 'c' => 'option C'); $fields['multi_example'] = array('type' => 'multi', 'options' => $options, 'value' => array('a', 'b'));
All of the following work if only one value is set, and none works if two values are set.
In all cases, the save works...the database gets updated correctly if 0, 1, or 2 values are set.
I was using version 1 in Fuel 0.93 with success though I was doing the form handling out of a controller and not via the model (never tested via model).
function form_fields($values = array()) { $fields = parent::form_fields($values); $options = array('FL' => 'FL', 'NY' => 'NY'); # Version 1 --- this is worked in 0.93 # $value = explode(",",$values['distribution']); # $fields['distribution'] = array('type' => 'multi', 'options' => $options, 'value'=>$value); # Version 2 -- this is just a test to see if they can be set following the example in the documentation # $fields['distribution'] = array('type' => 'multi', 'options' => $options, 'value'=>array('FL', 'NY')); # Version 3 $values ['distribution'] = explode(",",$values['distribution']); $fields['distribution'] = array('type' => 'multi', 'options' => $options); $fields['published']['order'] = 1000; return $fields; } public function on_before_save($values) { # Translate the data for distribution field back into a comma delimited format if (isset($values['distribution'])) {$values['distribution']= implode(",",$values['distribution']);} else {$values['distribution'] = '';}; return $values; }