I'm adding forms to my page using Zend/Form.
I'm adding elements by defining them as follows:
$this->add(array(
'name' => 'value',
'attributes' => array(
'type' => 'text',
'id' => 'value',
'autocomplete' => 'off',
'placeholder' => 'Cost',
),
'options' => array(
'label' => 'Cost',
),
));
As you can see there is a 'label' => 'cost' node, this generated a label to go with the input element.
How do I add classes, attributes to this label ?
Please try this, i haven't tested or used this, but going by the source it should function properly:
$this->add(array(
'name' => 'value',
'attributes' => array(),
'options' => array(
'label_attributes' => array(
'class' => 'mycss classes'
),
// more options
),
));
If this does not function, please leave me a comment. If it won't function, it is not possible using this approach, since the FormLabel
restricts the validAttributes
quite a bit:
protected $validTagAttributes = array(
'for' => true,
'form' => true,
);
This works well in Zend Framework 2.3 :
$this->add(array(
'name' => 'userName',
'attributes' => array(
'type' => 'text',
'class' => 'form-control',
'placeholder' =>'Username',
),
'options' => array(
'label' => 'Username',
'label_attributes' => array('class' => 'control-label')
),
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With