View Single Post
  #1 (permalink)  
Old 03-23-2008, 07:59 PM
friedhelm friedhelm is offline
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default Zend_Form: howto render

Hi,
sorry to ask such a simple newbie question, I just started to work with ZF.

Simplest form:
Code:
<?php
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$form = new Zend_Form();
$form->addElement('text', 'username');
$form->addElement('password', 'password');
$form->addElement('submit', 'login');
?>
No custom decorators, and nothing fancy ;-)
How do I output this form (I am not using any MVC)?
I know, that Zend_View is used by Zend_Form:
(Akra’s DevNotes Blog Archive Simple Zend_Form Example
I have red comment 39 by Matthew.
Obviously I got the error: ViewHelper decorator cannot render without a registered view object.
So, how Do I register a view object?

I googled around, searched the docs (15.2.3. Render a form), but:
echo $form;
or
echo $form->render();
errors out, view object for render is optional?

The docs say:
Quote:
By default, Zend_Form and Zend_Form_Element will attempt to use the view object initialized in the ViewRenderer, which means you won't need to set the view manually when using the Zend Framework MVC.
From this it follows that I have to set the view manually, if not using MVC.
How is this done?
Thanks,
Friedhelm
Reply With Quote