Is there a reliable way to create a custom view for a Zend_Form
? The decorators are pretty cryptic and using them in fancy ways sometimes is so complicated that I'd prefer to just write the HTML by hand. Is there a way to do it and still make the form fully cooperate with the controller (eg. call $form->isValid()
and expect everything to validate properly)? If so, are there any caveats to look out for (like taking care about validation errors display)?
The ideal solution would be to create a form and pass the elements array (containing the necessary data like names, IDs, input types and all needed to render the HTML) - does Zend Framework permit this?
[EDIT]
Instead of just echo
ing the form object, I have tried adding this code in the view (a simple login form):
<?php
$userid = $this->form->getElement('userid');
$pass = $this->form->getElement('password');
$remember = $this->form->getElement('remember');
$submit = $this->form->getElement('submit');
?>
<form enctype="<?php echo $this->form->getEnctype(); ?>" method="<?php echo $this->form->getMethod(); ?>" action="<?php echo $this->form->getAction(); ?>" id="<?php echo $this->form->getId(); ?>">
name: <input type="text" id="<?php echo $userid->getId(); ?>" name="<?php echo $userid->getName(); ?>" /><br />
pass: <input type="password" id="<?php echo $pass->getId(); ?>" name="<?php echo $pass->getName(); ?>" /><br />
remember: <input type="checkbox" id="<?php echo $remember->getId(); ?>" name="<?php echo $remember->getName(); ?>" /><br />
submit: <input type="submit" id="<?php echo $submit->getId(); ?>" name="<?php echo $submit->getName(); ?>" value="<?php echo $submit->getValue(); ?>" />
</form>
The form seems to work OK and validate (although I don't get redirected the the page I came from - but that's a different problem, I believe, as I pass that via GET
, not in the form). Is that acceptable, or am I doing something horridly wrong without knowing it?