You are not logged in.
Pages: 1
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
I've been wondering exactly the same (if I understad you correctly).
Offline
Maybe a good tutorial suggestion for you Jon ![]()
Offline
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
Have a look at this blog entry:
http://www.tibobeijen.nl/blog/2009/12/2 … mic-forms/
I think it may help you!
Offline
Pages: 1