Ahora mismo tengo esto:
Código PHP:
<?php
class Personas_Form_Persona extends ZendX_JQuery_Form{
public function __construct($options = null){
parent::__construct($options);
$this->setName('persona');
$id = new Zend_Form_Element_Text("id", array("readonly" => "readonly"));
$id->setLabel(utf8_encode('Código'))
->setAttrib("size", "4")
->setAttrib("maxlength ", "4");
$nombre = new Zend_Form_Element_Text('nombre');
$nombre->setLabel('Nombre')
->setAttrib("size", "70")
->setAttrib("maxlength ", "200")
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => 'El campo es obligatorio')));
$nomfiscal = new Zend_Form_Element_Text('nomfiscal');
$nomfiscal->setLabel('Nombre fiscal')
->setAttrib("size", "70")
->setAttrib("maxlength ", "200")
->addFilter('StripTags')
->addFilter('StringTrim');
$nif = new Zend_Form_Element_Text('nif');
$nif->setLabel('Nif')
->setAttrib("size", "15")
->setAttrib("maxlength ", "15")
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => 'El campo es obligatorio')));
$telefono = new Zend_Form_Element_Text('telefono');
$telefono->setLabel(utf8_encode('Teléfono'))
->setAttrib("maxlength ", "30")
->addFilter('StripTags')
->addFilter('StringTrim');
$fax = new Zend_Form_Element_Text('fax');
$fax->setLabel('Fax')
->setAttrib("maxlength ", "30")
->addFilter('StripTags')
->addFilter('StringTrim');
$direccion1 = new Zend_Form_Element_Text('direccion1');
$direccion1->setLabel(utf8_encode('Dirección'))
->addFilter('StripTags')
->addFilter('StringTrim');
$direccion2 = new Zend_Form_Element_Text('direccion2');
$direccion2->setLabel(utf8_encode('Dirección entrega'))
->addFilter('StripTags')
->addFilter('StringTrim');
$cp = new Zend_Form_Element_Text('cp');
$cp->setLabel(utf8_encode('Código postal'))
->addFilter('StripTags')
->addFilter('StringTrim');
$poblacion = new Zend_Form_Element_Text('poblacion');
$poblacion->setLabel(utf8_encode('Población'))
->addFilter('StripTags')
->addFilter('StringTrim');
$provincia = new Zend_Form_Element_Text('provincia');
$provincia->setLabel('Provincia')
->addFilter('StripTags')
->addFilter('StringTrim');
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email')
->addFilter('StripTags')
->addFilter('StringTrim');
$clave = new Zend_Form_Element_Password('clave');
$clave->setLabel('Clave')
->addFilter('StripTags')
->addFilter('StringTrim');
$contacto = new Zend_Form_Element_Text('contacto');
$contacto->setLabel('Persona contacto')
->addFilter('StripTags')
->addFilter('StringTrim');
$entidad = new Zend_Form_Element_Text('entidad');
$entidad->setLabel('Entidad')
->setAttrib("size", "4")
->setAttrib("maxlength ", "4")
->addFilter('StripTags')
->addFilter('StringTrim');
$oficina = new Zend_Form_Element_Text('oficina');
$oficina->setLabel('Oficina')
->setAttrib("size", "4")
->setAttrib("maxlength ", "4")
->addFilter('StripTags')
->addFilter('StringTrim');
$dg = new Zend_Form_Element_Text('dg');
$dg->setLabel(utf8_encode('Dígito control'))
->setAttrib("size", "2")
->setAttrib("maxlength ", "2")
->addFilter('StripTags')
->addFilter('StringTrim');
$ccc = new Zend_Form_Element_Text('ccc');
$ccc->setLabel(utf8_encode('Ccc'))
->setAttrib("size", "8")
->setAttrib("maxlength ", "8")
->addFilter('StripTags')
->addFilter('StringTrim');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton');
$this->addElements(array($id, $nombre, $nomfiscal, $nif, $telefono, $fax, $direccion1, $direccion2, $poblacion, $provincia, $cp, $email, $clave, $contacto, $entidad, $oficina, $dg, $ccc, $submit));
$this->setDecorators(
array(
"FormElements",
array("HtmlTag", array("tag" => "table")),
"Form"
)
);
$this->setElementDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td", "colspan" => "7")),
array("Label" , array("tag" => "th")),
array(array("tr" => "HtmlTag"), array("tag" => "tr"))
)
);
$this->getElement('telefono')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "td")),
array(array("tr" => "HtmlTag"), array("tag" => "tr", 'openOnly' => true))
)
);
$this->getElement('fax')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "td")),
array(array("tr" => "HtmlTag"), array("tag" => "tr", 'closeOnly' => true))
)
);
$this->getElement('entidad')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "th")),
array(array("tr" => "HtmlTag"), array("tag" => "tr", 'openOnly' => true))
)
);
$this->getElement('oficina')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "th")),
)
);
$this->getElement('dg')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "th")),
)
);
$this->getElement('ccc')->setDecorators(
array(
"ViewHelper",
array("HtmlTag", array("tag" => "td")),
array("Label" , array("tag" => "th")),
array(array("tr" => "HtmlTag"), array("tag" => "tr", 'closeOnly' => true))
)
);
}
}
?>
No se si es que esto de los decorators está un poco limitado o que yo no me entero bien de que va el tema. Supongo que al final me decantaré por los ViewScript Decorators que según dicen, tienes más control.
De todas maneras esta estructura que tengo ahora mismo me vale, no es lo que yo quería exactamente, pero no está mal.