En el controlador tengo esto:
Código PHP:
$form = new Admin_Form_Interesados();
$form->addPrefixPath('Admin_Forms_Decorators', 'Admin/Forms/Decorators/Interesados', 'Interesados');
$this->view->form;
Código PHP:
class Admin_Form_Interesados extends Zend_Form{
protected $form;
public function __construct($options = null) {
parent::__construct($options);
//$this->setName('interesados');
// $this->addPrefixPath('Admin_Form_Decorator_Interesados', 'Admin/Form/Decorator/Interesados','decorator');
$nombre = new Zend_Form_Element_Text('nombre');
$nombre->setLabel('Nombre')
->setRequired(true)
->addFilter('StringTrim');
$nif = new Zend_Form_Element_Text('nif');
$nif->setLabel('Nif/CIF')
->setRequired(true)
->addFilter('StringTrim');
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email')
->setRequired(true);
$this->addElements(array($nombre,$nif,$email));
$this->setDecorators(array('FormElements',array('HtmlTag',
array('tag'=>'dl','class'=>'Zend ')),
array('Interesados',array(
'placement'=>'PREPEND','text'=>'Estos campos son obligatorios')),
'Form')) ;
}
Código PHP:
class Admin_Forms_Decorators_Interesados extends Zend_Form_Decorator_Abstract
{
protected $_placement = 'PREPEND';
public function buildLabel($content){
if(null===($element = $this->getElement())){
return $content;
}
$label = $element->getName();
if($element->isRequired()){
$text = $this->getOption('text');
$output = '<p class="requerido"> ' . $text . '</p>';
$label .= '*';
}
$label .= ':';
if (null === ($view = $element->getView())) {
return $this->render($content, $label);
}
$label = $view->formLabel($element->getName(), $label);
return $this->render($content, $label);
}
public function render($content,$newContent=null,$output=null)
{
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$output = $this->buildLabel();
switch ($placment) {
case 'APPEND':
// append original content with new content
return $output . $content . $separator . $newContent;
case 'PREPEND':
// prepend original content with new content
return $newContent . $separator . $content . $output;
default:
// replace otherwise
return $newContent;
}
}
}