Zend Framework: group buttons in single line in Zend_Form

Aim: group buttons generated by Zend_Form in single line (“Update” and “Delete”).

Solution: use decorators and DisplayGroup.

		$this->addElement (new Zend_Form_Element_Submit('submit', array(
            	'label'	=> 'Update',
        		'class'	=>	'ui-state-default ui-corner-all ui-button',
				'decorators'	=>	array('ViewHelper')
		  	))
		);

        $this->addElement (new Zend_Form_Element_Button('delete', array(
            	'label'	=> 'Delete',
        		'id'	=>	'delete-button',
        		'class'	=>	'ui-state-default ui-corner-all ui-button',
        		'decorators'	=>	array('ViewHelper')
        	))
        );

       $this->addDisplayGroup(array('submit', 'delete'), 'submitButtons', array(
	        'decorators' => array(
	            'FormElements',
	            array('HtmlTag', array('tag' => 'div', 'class' => 'form-buttons')),
	        ),
	   ));

Here $this — children of class Zend_Form (class Application_Model_Form_User extends Zend_Form).
You should get something like this:

Example of interface with buttons grouped in one line

Example of interface with buttons grouped in one line

How does it work?

For every element we’ve removed all decorators except one, which shows element by itself. These elements without decorators we’ve added to one visual group based on div. To support styling in CSS we’ve added class “form-buttons” to this group.