I have some problem to create "three columns table" form in Zend Framework:
I already have Zend Form decorated by tow columns table:
Table have two column, first one is for label and second one is for Zend_Form_Element, that works well, but, I want to add third column and put there small image - question mark, where I will setup javascript.
How to set decoration for that?
Current decoration for two columns table is:
<?php
class Application_Form_Login extends Zend_Form {
public function init() {
// create decoration for form's elements
$elementDecoration = array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'td', 'valign' => 'TOP')),
array('Label', array('tag' => 'td')),
array('Errors'),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
);
$buttonDecoration = array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
$formDecoration = array(
'FormElements',
array(array('data'=>'HtmlTag'), array('tag'=>'table', 'class'=>'forms')),
'Form'
);
// create form elements
$username = new Zend_Form_Element_Text("username");
$username->setLabel('Username: ')
->setDecorators($elementDecoration);
$password = new Zend_Form_Element_Password("password");
$password->setLabel('Password: ')
->setDecorators($elementDecoration);
$submit = new Zend_Form_Element_Submit('Login');
$submit->setLabel('LOGIN')
->setDecorators($buttonDecoration);
$this->setDecorators($formDecoration);
// set created form elements
$this->setAction('')
->setMethod('post')
->addElement($username)
->addElement($password)
->addElement($submit);
}
}
It depends on if you only require to add <td class="fieldTip"></td>
, or if you need to add things inside the <td></td>
.
In the first case you just need to add a simple HtmlTag decorator right after the Label decorator :
array('HtmlTag', array('tag'=>'td','class'=>'fieldTip','placement'=> 'APPEND'))
If you want to put some sort of description of the field you should play with the Description decorator, and the $element->setDescription() method, and do some css/js after, to display it as a tooltip.
EDIT
I just answered an other question about simple custom decorators, you'll find what you need in the example i give there Zend Form Element with Javascript - Decorator, View Helper or View Script?. Just replace the <script>
part with whatever you need.