Skip to content

Instantly share code, notes, and snippets.

@fernandomm
Created January 26, 2012 02:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandomm/1680654 to your computer and use it in GitHub Desktop.
Save fernandomm/1680654 to your computer and use it in GitHub Desktop.
Zend Form decorators for Twitter Bootstrap
<?php
$form = new Zend_Form();
// Add your elements here
$form->removeDecorator('HtmlTag');
$elementNames = array();
foreach ($form->getElements() as $element) {
// Set specific decorators for each type of element
if ($element instanceof Zend_Form_Element_Submit
|| $element instanceof Zend_Form_Element_Button) {
$element->setDecorators(array(
'ViewHelper',
array(
array(
'row' => 'HtmlTag',
),
array(
'tag' => 'div',
'class' => 'actions'
)
)
));
} elseif ($element instanceof Zend_Form_Element_Hidden) {
$element->setDecorators(array(
'ViewHelper',
));
} else {
$element->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(
array(
'data' => 'HtmlTag',
),
array(
'tag' => 'div',
'class' => 'input'
)
),
array(
'Label',
),
array(
array(
'row' => 'HtmlTag',
),
array(
'tag' => 'div',
'class' => 'element-wrapper clearfix '. ($element->hasErrors() ? 'error' : ''),
'id' => 'wrapper-'. $element->getId()
)
)
));
}
$elementNames[] = $element->getName();
}
// Add all elements on a default display group
$form->addDisplayGroup($elementNames, 'default');
$form->getDisplayGroup('default')
->removeDecorator('HtmlTag');
$form->getDisplayGroup('default')
->removeDecorator('DtDdWrapper');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment