-- 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/