I forgot to state in the last message:

        ->setIsArray(false) 

This is the key here to turn a field into a drop down select statement. The
default creates an array based name select input which leads to a multi
select input:

->setIsArray(false) 

<select name="my_select_field" id="my_select_field">

->setIsArray(true) 

<select name="my_select_field[]" id="my_select_field" multiple="multiple">



gammamatrix wrote:
> 
> I would not necessarily call it broken. Here is how to get what you need:
> 
> // Start code
> 
> $form = new Zend_Form();
> 
> $my_select_field_options = array(
>       '1'             => '1 fish',
>       '2'             => '2 fish',
>       'red'   => 'red fish',
>       'blue'  => 'blue fish',
> );
>               
> $my_select_field = $form->addElement('select', 'my_select_field')
>       ->getElement('my_select_field')
>       ->addMultiOptions($my_select_field_options)
>       ->setIsArray(false)
>       ->setValue('red')
>       ->setLabel('My Select Field Label');
> 
> echo '<br />' . $my_select_field;
>       
> $my_select_array_field = $form->addElement('select', 'my_select_field')
>       ->getElement('my_select_field')
>       ->addMultiOptions($my_select_field_options)
>       ->setIsArray(true)
>       ->setValue('blue')
>       ->setLabel('My Select Array Field Label');
> 
> echo '<br />' . $my_select_array_field;
> 
> $my_multi_field = $form->addElement('multiselect', 'my_multi_field')
>       ->getElement('my_select_field')
>       ->addMultiOptions($my_select_field_options)
>       ->setIsArray(true)
>       ->setValue('red')
>       ->setLabel('My Multi Field Label');
> 
> echo '<br />' . $my_multi_field;
> 
> // End Code
> 
> <!-- Start Output -->
> 
> <br /><dt><label for="my_select_field" class="optional">My Select Field
> Label</label></dt>
> <dd>
> <select name="my_select_field" id="my_select_field">
>     <option value="1" label="1 fish">1 fish</option>
>     <option value="2" label="2 fish">2 fish</option>
>     <option value="red" label="red fish" selected="selected">red
> fish</option>
>     <option value="blue" label="blue fish">blue fish</option>
> 
> </select></dd><br /><dt><label for="my_select_field" class="optional">My
> Select Array Field Label</label></dt>
> <dd>
> <select name="my_select_field[]" id="my_select_field" multiple="multiple">
>     <option value="1" label="1 fish">1 fish</option>
>     <option value="2" label="2 fish">2 fish</option>
>     <option value="red" label="red fish">red fish</option>
>     <option value="blue" label="blue fish" selected="selected">blue
> fish</option>
> </select></dd><br /><dt><label for="my_select_field" class="optional">My
> Multi Field Label</label></dt>
> 
> <dd>
> <select name="my_select_field[]" id="my_select_field" multiple="multiple">
>     <option value="1" label="1 fish">1 fish</option>
>     <option value="2" label="2 fish">2 fish</option>
>     <option value="red" label="red fish" selected="selected">red
> fish</option>
>     <option value="blue" label="blue fish">blue fish</option>
> </select></dd>
> 
> <!-- End Output -->
> 
> 
> mrolli wrote:
>> 
>> 
>> Jeffrey Sambells-2 wrote:
>>> 
>>> The problem however is that for some reason it renders as a multi  
>>> select (with multiple="multiple"):
>>> 
>> 
>> Same problem here:
>> 
>> example1
>>         $location_id = new Zend_Form_Element_Select('location_id');
>>         $location_id->setLabel('ticket_locations')
>>                     ->setRequired(true)
>>                     ->addMultiOption('', null);
>> 
>> example2
>>         $location_id = new Zend_Form_Element_Multiselect('location_id');
>>         $location_id->setLabel('ticket_locations')
>>                     ->setRequired(true)
>>                     ->addMultiOption('', null);
>> 
>> Both render as <select name="location_id[]" multiple="multiple" .../>
>> whereas the former schould render as <select name="location_id" .../>
>> without the multiple attribute.
>> 
>> This is a new bug I think because this once worked like a charm but since
>> about a week (without changing my code) the HEAD seems broken.
>> 
>> Regard Michael
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-select-element-always-multi--tp15889624s16154p15891096.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to