views:

37

answers:

1

Hi,

Why Zend_Form produce <dl> <dt id="label-id"> <dd id="elem-id"> </dl> ? (I understand that its produce by default decorators, but why and for what they used? )

Thanks

+3  A: 

The decorators are a way to wrap your form elements.

In Zend/Form.php you can see the default configuration:

/**
 * Load the default decorators
 *
 * @return void
 */
public function loadDefaultDecorators()
{
    if ($this->loadDefaultDecoratorsIsDisabled()) {
        return $this;
    }

    $decorators = $this->getDecorators();
    if (empty($decorators)) {
        $this->addDecorator('FormElements')
             ->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
             ->addDecorator('Form');
    }
    return $this;
}

Plus Zend/FormElements.php uses its own decorators:

/**
 * Load default decorators
 *
 * @return Zend_Form_Element
 */
public function loadDefaultDecorators()
{
    if ($this->loadDefaultDecoratorsIsDisabled()) {
        return $this;
    }

    $decorators = $this->getDecorators();
    if (empty($decorators)) {
        $this->addDecorator('ViewHelper')
            ->addDecorator('Errors')
            ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
            ->addDecorator('HtmlTag', array('tag' => 'dd',
                                            'id'  => $this->getName() . '-element'))
            ->addDecorator('Label', array('tag' => 'dt'));
    }
    return $this;
}

You can overwrite the default decorators for each element or for the whole form:

$element->setDecorators(array(
    'ViewHelper',
    'Description',
    'Errors',
    array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')),
    array(array('td' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
));

There is a really easy podcast explaining how decorators work:

http://feeds.feedburner.com/ZendScreencastsVideoTutorialsAboutTheZendPhpFrameworkForiPhone

Look for the video called: Zend_Form Decorators Explained

Ghommey
thank you very much, but my question is why and not how.I mean I dont know why should be dd tags added by zend_form - soo i asking if exist special reason for that
Yosef
It is just a search engine and screen reader friendly presentation of the form.
Ghommey