-- Jacky Chen <[EMAIL PROTECTED]> wrote
(on Saturday, 03 May 2008, 03:54 PM +0800):
> I add an select element to the Zend_Form,like this,
>
> $course = new Zend_Form_Element_Select('course[]');
> $form->addElement($course);
>
> And,the name of the course element would be course,not course[],except that i
> set the multiple attribute of the element to true. But i won't this style of
> multiple select, i would like to multiple select elements.
>
> Example:
> > i want the style of multiple select like this:
> <select name="course[]">
> <option value="value">course option></option>
> ......
> </select>
> <select name="course[]">
> <option value="value">course option</option>
> ......
> </select>
>
> > not the style of this:
> <select name="course[]" multiple="multiple">
> <option value="value">course option</option>
> ......
> </select>
>
> Then i look for the code,and i found that in the setName() method of
> Zend_Form_Element class, it call the filterName() method with default value of
> false to $allowBrackets parameter,then it always filter out the brackets.
This functionality is setup so that iteration and overloading work.
For what you want, you should use a sub form, and attach your various
select elements to that subform; that way they will be namespaced and
you can fetch all values as an array.
Another option is to create a custom element that creates all of the
selects; in the subclass set the '_isArray' property true, which will
ensure that the name has the '[]' appended when you pass the values to
the form helpers.
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/