I'm trying to solve a very similar problem at the moment using
Zend_Form.
Calling $element->setIsArray (true); basically does what you're after,
however
I've found that the select view renderer will automatically detect
square
brackets at the end of a name and output a multi-select rather than a
single
select.
There doesn't seem to be anyway around this, and this is one clear use-
case
that doesn't require a multi-select element for names ending with '[]'.
Obviously automatically outputting a multiple select is the intended
behavior,
but could we perhaps somehow disable this feature?
--
Mathew byrne
http://www.matbyrne.com/
On Apr 28, 2008, at 11:22 AM, Matthew Weier O'Phinney wrote:
-- OakBehringer <[EMAIL PROTECTED]> wrote
(on Sunday, 27 April 2008, 05:20 PM -0700):
Say you have the following form for adding types of poop to
[whatever]. On
this form, you don't know how many types of poop the user may want
to add,
so you have a bit of javascript that simply adds elements to the
DOM when
the user clicks a "Add Another Type" button. This could result in the
following:
<input type="text" name="type[]" />
<input type="text" name="type[]" />
<input type="text" name="type[]" />
This could be iterated by doing the following:
foreach($_POST['type'] as $type) {
// access value here ($type)
}
From what I can tell, accessing dynamic fields on the server side
cannot be
done using Zend_Form.
What have you tried? The above should be possible with the right
combination of filters and validators; elements do not have to be
scalar
values (take a look at the various 'Multi' elements, such as Radio,
Multiselect, and MultiCheckbox, for example).
The below should work -- and it should work without the foreach()
even.
If it doesn't, please let me know.
It would be so nice to be able to do something like this:
$poop = new Zend_Form();
$type = new Zend_Form_Element_Text('type', array(
'validators' => array('NotEmpty', ... etc),
'filters' => array('StringTrim', ... etc)
))
$poop->addElement($type);
and follow up the code with something like...
foreach ($type as $singleType) {
// Handle data here
}
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/