Hi, I'm trying to add a title attribute to the inp开发者_Python百科ut element created this way
$this->createElement('text', 'tv_id', array(
'label' => 'Tv Id',
'class' => 'htmlfivify_number',
'readonly' => 'True',
'required' => False,
'filters' => array('Int'),
'validators' => array('Digits', 'Int')
));
I tried adding a 'title' = "some title text'
in the options but it didn't show up,
I want to add this title attribute so that it shows up as a tooltip when the user mouse overs an input.
How can this be achieved?
$element = $this->createElement('text', 'tv_id', array(
'label' => 'Tv Id',
'class' => 'htmlfivify_number',
'readonly' => 'True',
'required' => False,
'filters' => array('Int'),
'validators' => array('Digits', 'Int')
));
$element->setAttrib('title', 'My title text');
Should get you your title.
From the ZF manual
Form elements may require additional metadata. For XHTML form elements, for instance, you may want to specify attributes such as the class or id. To facilitate this are a set of accessors:
setAttrib($name, $value): add an attribute
setAttribs(array $attribs): like addAttribs(), but overwrites
getAttrib($name): retrieve a single attribute value
getAttribs(): retrieve all attributes as key/value pairs
Most of the time, however, you can simply access them as object properties, as Zend_Form_Element utilizes overloading to facilitate access to them:
// Equivalent to $element->setAttrib('class', 'text'): $element->class = 'text; <="" span="">
By default, all attributes are passed to the view helper used by the element during rendering, and rendered as HTML attributes of the element tag.
so you could also do $element->title = 'My title text'
精彩评论