-- Julian Davchev <[EMAIL PROTECTED]> wrote
(on Friday, 27 June 2008, 11:43 AM +0300):
> Hi,
> Kinda hard to explain this but will give a shot :)
>
> I have a form... let's say it's about address. we have
> 'address_street' and 'address_block' fields in there.
>
> I want on the page to be able to add arbitrary number of addresses.
> So when building the form I get something like these input field names
> in the finally generated form. address[1][address_street]
> address[1][address_block] - link to add_more/remove
> address[2][address_street] address[2][address_block] - link
> to add_more/remove
>
> I want to uze Zend_Form component so I can benefit of showing error
> messages, prefill, validate etc.
>
> So issues I have are:
> 1. How do I build that form in first place - Was thinking of some way of
> using Sub_Form but not really sure
1. Build a standard sub form with the required elements
2. Instantiate, and call setName() on it with a unique name
3. Attach to the master form
4. Repeat from 1 as necessary.
> 2. How do I validate those thingies.. and show errors for each correct
> block.
When they are attached as sub forms, you simply validate the form. Since
each sub form will have a unique name, you don't have to worry about
anything; it should "just work."(tm)
> 3. This is dynamic..can be N number of such forms.
Start with a common identifier 'address', and attach the sub forms in a
loop, appending an integer identifier:
for ($i = 1; $i < 11; ++$i) {
$subForm = new My_Form_Address();
$form->addSubForm($subForm, $address . $i);
}
> I was thinking of using a form to which I assign N number of Sub_Form
> each of which contains address_street and address_block fields
> but not really sure how exactly to make it finally render like
> described.
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/