Studyon Minte9.com
ZF 1.0




Decorators



#modules/default/controllers/FrontendController.php
<?php
	...
	$form = new Forms_Login(); // modules/default/Forms
	$this->view->loginForm = $form;

#modules/default/Forms/Login.php
<?php
class Forms_Login extends Zend_Form {
	
	public function init() {
		
		// elements
		$username = $this->createElement('text','username');
		$username->setRequired(true);
		$username->setLabel('Username');
			
		$password = $this->createElement('password','password');
		$password->setRequired(true);
		$password->setLabel('Password');
			
		$submit = new Zend_Form_Element_Submit("submit");
		$submit->setLabel("Submit");
			
		// decorators
		$username->setDecorators(array(
			'ViewHelper',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'td')),
			array('Label', array('tag' => 'td')),
			array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
		));
		$password->setDecorators(array(
			'ViewHelper',
			'Description',
			'Errors',
			array(array('data'=>'HtmlTag'), array('tag' => 'td')),
			array('Label', array('tag' => 'td')),
			array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
		));
		$submit->setDecorators(array(
			'ViewHelper',
			'Description',
			'Errors', 
			array(array('data'=>'HtmlTag'), array('tag'=>'td', 'colspan'=>'2','align'=>'center')),
			array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
		));
		$this->setDecorators(array(
		       'FormElements',
		       array(array('data'=>'HtmlTag'),array('tag'=>'table')),
		       'Form'
		));

			
		// add elements
		$this->addElements(array(
			$username,
			$password,
			$submit,
		));

	}
}

#modules/default/views/scripts/frontend/login.phtml
<?php 
	echo $this->loginForm;


http://zendgeek.blogspot.com/2009/07/zend-form-decorators.html
http://stackoverflow.com/questions/3796967/zend-form-decorators-error-in-table