Results 1 to 3 of 3

Thread: Form Select - Defaults to multi when name ends with []

  1. #1
    lysender is offline Junior Member
    Join Date
    Oct 2008

    Default [Solved] Form Select - Defaults to multi when name ends with []

    Hello there,

    I have this form that has subforms (my own implementation of model because I'm not a Zend_Form user) and all my elements on a subform ends with [] of course and that is the same as what subforms are used to be in Zend if I'm not mistaken.

    $s = new Zend_View_Helper_FormSelect;
    $s->formSelect($name, $value, $attribs, $choices);
    However, I have this SELECT element and because it ends with [], it is rendered as a multi-select element - which I don't want it that way.

    I have to edit Zend_View_Helper_FormSelect and commented out some parts so that the element is not set into multi if it ends with []. I only want it multi when I set the attribute.

            $value = array_map('strval', (array) $value);
            // check if element may have multiple values
            $multiple = '';
            // patched, remove this so that multiple is not set by default
            //if (substr($name, -2) == '[]') {
                // multiple implied by the name
                //$multiple = ' multiple="multiple"';
            if (isset($attribs['multiple'])) {
    I am not using the SELECT element as a multiple select because it is on a subform. Each row, there is a SELECT element.

    Is this a bug or there is a documented option to set this?

    Last edited by lysender; 07-06-2010 at 02:22 AM.

  2. #2
    LuCarD is offline Member
    Join Date
    Jun 2010


    It is a feature

    But if you create the element like this it should work

    $element = new Zend_Form_Element_Select('selectbox', array('multiple' => false )) ;

  3. #3
    lysender is offline Junior Member
    Join Date
    Oct 2008


    I'm not using any Zend_Form_*. I was using Zend_View_Helper_Select.

    But that helps dude! I examined the attribs part of Zend_View_Helper_Select and found out that it removes the multi if multiple is false.

    Before, I think that the attribs only represents attrib="value", but when I take a closer look, select was a different case. It indeed removes it by this line:

                if ($attribs['multiple']) {
                    // True attribute; set multiple attribute
                    $multiple = ' multiple="multiple"';
                    // Make sure name indicates multiple values are allowed
                    if (!empty($multiple) && (substr($name, -2) != '[]')) {
                        $name .= '[]';
                } else {
                    // False attribute; ensure attribute not set
                    $multiple = '';
    The ELSE part.

    So I now need to revert my patch and alter my code:

    	 * Initialize class
    	 * @return void
    	public function init()
    		$this->_fields += array(
    			'companion_id'			=> array(),
    			'reservation_id'		=> array(),
    			'companion_title'		=> array(
    				'required'				=> true,
    				'viewHelpers'			=> array(
    					'formSelect'			=> array(
    						'attribs'				=> array(
    							'multiple'				=> false
    Thanks a lot!

Similar Threads

  1. Populating multi select form element for Editing data
    By php_reddy in forum Core Infrastructure
    Replies: 1
    Last Post: 04-28-2010, 04:04 PM
  2. multi stage form comletion (begging for help)
    By topcatxx in forum Concepts, Ideas, Planning
    Replies: 0
    Last Post: 11-02-2009, 08:54 PM
  3. Help with _getAllParams and Multi-Select Return Values
    By johnlamont in forum Model-View-Controller (MVC)
    Replies: 3
    Last Post: 06-21-2009, 01:04 PM
  4. Zend Form Multi Option
    By bwaine in forum General Q&A on Zend Framework
    Replies: 3
    Last Post: 05-05-2009, 08:25 PM
  5. Zend Form Multi Elements
    By sintec in forum Core Infrastructure
    Replies: 1
    Last Post: 09-04-2008, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts