[Solar-talk] form select options
Paul M Jones
pmjones at solarphp.com
Tue Nov 6 13:04:29 CST 2007
On 06 Nov 2007, at 13:51, Jeff Surgeson wrote:
> Hi
>
> Anyone tell me why when I create a data object save the following
> it saves
> the numeric array key 0, 1 or 2 as apposed to the array value?
>
> ......etc
> $item = $this->_gallery->fetchNew();
> $data = $this->_request->post('gallery', array());
> $item->load($data, $cols);
> ......etc
> // get the form from the record
> $form = $item->form($cols);
> ....etc
> $form->setElements(array(
> 'gallery[main_cat]' => array(
> 'type' => 'select',
> 'options' => array('family', 'children', 'babies'),
It looks like the options array is keyed numerically. For select
options, the array key is used as the database value and the array
value is the displayed label. Thus, to save the words instead of the
numbers, you would need:
'options' => array(
'family' => $this->locale('OPTION_FAMILY'),
'children' => $this->locale('OPTION_CHILDREN'),
'babies' => $this->locale('OPTION_BABIES'),
),
Hope that helps, let me know if it does not.
-- pmj
More information about the Solar-talk
mailing list