Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-04-19 03:08:41

Ryan Johnston
Member
Registered: 2010-03-08
Posts: 21

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

Offline

#2 2010-04-21 17:27:41

harri
Member
From: Kristiansand, Norway
Registered: 2009-12-02
Posts: 27
Website

Re: Dynamic Zend_Form ?

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

Offline

#3 2010-04-21 19:31:01

Ryan Johnston
Member
Registered: 2010-03-08
Posts: 21

Re: Dynamic Zend_Form ?

Maybe a good tutorial suggestion for you Jon tongue

Offline

#4 2010-04-21 19:41:15

iznogood
Member
From: Montreal
Registered: 2009-12-17
Posts: 20
Website

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.

Offline

#5 2010-10-19 10:05:03

rafa_esteller
New member
Registered: 2010-10-19
Posts: 1

Re: Dynamic Zend_Form ?

Have a look at this blog entry:
http://www.tibobeijen.nl/blog/2009/12/2 … mic-forms/
I think it may help you!

Offline

Board footer

Powered by FluxBB