thanks, subforms seem to be way to go.
Re the valid php variable names, I was thinking of extending Zend_Form to work
around this specifically removing the preg_replace on line 823 and wrinting a
processor for looking for the first array form as an integer and thus know that
it is an update (if empty, know that it's an insert). But I'm a little nervous
changing overriding filterName like this. Is there anything that could cause
problems?
817 public function filterName($value, $allowBrackets = false)
818 {
819 $charset = '^a-zA-Z0-9_\x7f-\xff';
820 if ($allowBrackets) {
821 $charset .= '\[\]';
822 }
823 //return preg_replace('/[' . $charset . ']/', '', (string) $value);
824 return (string) $value;
825 }
which would allow me to do something like this:
155 $form=new Zend_Form();
156 $form->setAction('/fadmin/app/filter/show/')->setMethod('post');
157 $form->addElement('text','group_name');
158
$points=array(array('id'=>1,'first_name'=>'Amanda','last_name'=>'Salter'),
159
array('id'=>2,'first_name'=>'Britney','last_name'=>'Goin'));
160
161 foreach($points as $row){
162 $sub=new Zend_Form_SubForm();
163 $fn=new Zend_Form_Element_Text('first_name_new');
164 $fn->setBelongsTo(69);
165 $sub->addElements(array($fn));
166 //$options=array('elementPrefixPath'=>array(12,14,16));
167 //$sub->setOptions($options);
168
169 if($sub instanceof Zend_Form){
170 echo "this is an instance of Zend_Form!<br/>";
171 }
172 $forms['users['.$row['id'].']']=$sub;
173 //$form->addSubForm($sub,'bird');
174
175 }
176 $form->addSubForms($forms);
177 $form->addElement('submit','click on me!');
178 $this->view->form=$form;
179 }
and render into:
<input type="text" name="users[1][first_name_new]" id="users-1-first_name_new"
value=""><br/>
<input type="text" name="users[2][first_name_new]" id="users-2-first_name_new"
value=""><br/>
________________________________
From: Matthew Weier O'Phinney <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, November 11, 2008 10:33:13 AM
Subject: Re: [fw-general] Zend_Form and html array syntax. is this possible?
-- Joe Theplumber <[EMAIL PROTECTED]> wrote
(on Tuesday, 11 November 2008, 09:02 AM -0800):
> New to some of the Zend_Form pieces and trying to migrate some old code to ZF.
> I was curious whether there is a way to use Zend_Form with html array syntax
> and have Validation and Filtering work.
Use sub forms. Sub forms are for exactly this sort of semantic grouping,
and by default render using array notation. Sub forms may be nested
infinitely deep.
One note, however: form element names must be valid PHP variable names
-- so numeric keys simply will not work currently.
> I would like to have a form like this:
> <form method='post' action='/controller/action'>
> <input type='text' name='node[23][name]'>
> <input type='text' name='node[25][name]'>
> <input type='text' name='node[28][name]'>
> <input type='submit' value='click me'>
> </form>
>
> Seems pretty standard but Zend_Form when created like this wants to flatten it
> out:
> $form=new Zend_Form();
> $form->setAction('/controller/action/')->setMethod('post');
> $main_header=$form->addElement('text','node[23][name]', array('label'=>'Menu
> Header'));
> $main_header=$form->getElement('node[23][name]')
> ->setRequired(true);
> $submit=$form->addElement('submit','submit');
>
> will make node[23][name] into node23name? Is there any way to support this via
> Zend_Form (and ideally on the converse Model object)?
>
> here's something close:
> http://davidcaylor.com/php/building-table-based-forms-in-zend_form
>
> thanks,
>
> jt
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/