Created
January 26, 2012 02:50
-
-
Save fernandomm/1680654 to your computer and use it in GitHub Desktop.
Zend Form decorators for Twitter Bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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