1

Topic: Dynamic Zend_Form ?

Hi,

Is it possible to create a Zend_Form with dynamic elements?

What I mean is say when a user changes an option in a select box of the Zend_Form it then uses jQuery to pull extra elements from Zend_Form and populate. Then when you post the form it validates correctly based on the elements that were presented in the Dynamic Zend_Form.

Cheers,
Ryan

2

Re: Dynamic Zend_Form ?

I've been wondering exactly the same (if I understad you correctly).

3

Re: Dynamic Zend_Form ?

Maybe a good tutorial suggestion for you Jon tongue

4

Re: Dynamic Zend_Form ?

You should be able to create a class that extends Zend_Form.

class SomeForm extends Zend_Form
{
   public function init($fields_array)
   {
        foreach($fields_array as $field){

           $this->addElement('textarea', $field->name, array(
        'label'      => $field->label,
        'required'   => $field->required,
        'rows'       => $field->rows,
        'cols'       => $field->cols,
        'validators' => array(
        'NotEmpty',
        )
        ));
         }     
     }
}

Add a switch statement to switch between different field types and you should be good. There is probably a better solution but this one should work pretty well.

BTW I wrote the code directly here so there could be errors.