Here's an update for ZF2.
You'll have to use this in your Zend\Form\Form :
$this->add(
[
'name' => 'q',
'type' => 'Text',
'options' => [
'label' => 'Search',
],
'attributes' => [
'placeholder' => 'Search',
],
]
);
setAttrib
doesn't exists, but setAttribute
does :
$element->setAttribute('placeholder', 'Search');
But in FormText
view-helper, you can't add options anymore, so you have to do :
$element = $form->get('q');
$saved_placeholder = $element->getAttribute('placeholder'); // works even if not defined
$element->setAttribute('placeholder', 'Search');
echo $this->formText($element);
$element->setAttribute('placeholder', $saved_placeholder);
I know, this is an ugly hack !