I too find the default decorators to be a massive pain. I understand why they are the way they are, but I think the 'inconvenience factor' has been grossly underestimated.
Anyway, I would recommend using ViewScripts for your forms. Note that these are not the same as Views -- instead, ViewScripts are referenced explicitly in your Form class, act as a "sub-view" of sorts and allow you to control the layout of each and every element. Examples how to use ViewScripts have been somewhat hard to find in the past, but I'll try to take a stab at providing something useful.
First, override loadDefaultDecorators in your form class:
public function loadDefaultDecorators() {
$this->setDecorators(
array(
array('ViewScript',
array('viewScript' => 'foo/bar.phtml')
)
)
);
}
This will reference a ViewScript named bar.phtml located in /views/scripts/foo. Note the case-sensitive differences in "ViewScript" and "viewScript" above.
Next, you'll have to tweak the decorators applied to each element to ensure it displays but without the annoying dt/dd wrappers. For instance:
$baz = new Zend_Form_Element_Text('bazInput');
$baz->setDecorators(array('ViewHelper','Errors'));
Finally, you'll need to build your ViewScript, such as:
<form method="post" action="<?php echo $this-element->getAction() ?>">
<table>
<tr>
<td><label for="bazInput">Baz:</label></td>
<td><?php echo $this->element->bazInput ?></td>
</tr>
</table>
<input type="submit" value="Submit Form" />
</form>
Obviously this is a very simple example, but it illustrates how to reference the form elements and form action.
Then in your View, simply reference and output your form as usual. This way you can have much finer control over your form layouts -- to include easily adding Javascript.
I believe this approach resolves both your requirements: you can build forms in plain HTML and still take advantage of the Zend Form validation mechanism.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…