Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Dojo Form Elements and Decorators

Building on the dijit view helpers, the Zend_Dojo_Form family of classes provides the ability to utilize Dijits natively within your forms.

There are three options for utilizing the Dojo form elements with your forms:

  • Use Zend_Dojo::enableForm(). This will add plugin paths for decorators and elements to all attached form items, recursively. Additionally, it will dojo-enable the view object. Note, however, that any sub forms you attach after this call will also need to be passed through Zend_Dojo::enableForm().

  • Use the Dojo-specific form and subform implementations, Zend_Dojo_Form and Zend_Dojo_Form_SubForm respectively. These can be used as drop-in replacements for Zend_Form and Zend_Form_SubForm, contain all the appropriate decorator and element paths, set a Dojo-specific default DisplayGroup class, and dojo-enable the view.

  • Last, and most tedious, you can set the appropriate decorator and element paths yourself, set the default DisplayGroup class, and dojo-enable the view. Since Zend_Dojo::enableForm() does this already, there's little reason to go this route.

Example 357. Enabling Dojo in your existing forms

"But wait," you say; "I'm already extending Zend_Form with my own custom form class! How can I Dojo-enable it?'"

First, and easiest, simply change from extending Zend_Form to extending Zend_Dojo_Form, and update any places where you instantiate Zend_Form_SubForm to instantiate Zend_Dojo_Form_SubForm.

A second approach is to call Zend_Dojo::enableForm() within your custom form's init() method; when the form definition is complete, loop through all SubForms to dojo-enable them:

class My_Form_Custom extends Zend_Form
    public function 
// Dojo-enable the form:

// ... continue form definition from here

        // Dojo-enable all sub forms:
foreach ($this->getSubForms() as $subForm) {

Usage of the dijit-specific form decorators and elements is just like using any other form decorator or element.

Zend Framework