Yasser1984
Yasser1984

Reputation: 2451

Title for zend framework input elements

Hi, I'm trying to add a title attribute to the input 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?

Upvotes: 0

Views: 1935

Answers (1)

vascowhite
vascowhite

Reputation: 18440

$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'

Upvotes: 1

Related Questions