Sasha
Sasha

Reputation: 8705

Yii2 attributeLabels - wrap part of the label in a tag

Inside User model, I am using attributeLabels method to create text for the field:

public function attributeLabels()
    {
        return [
            'terms'            => 'I accept the Terms and Coditions'
        ];
    }

And in the view I am using standard $form->field method to show the input field:

<?php $form->field($model, 'terms')->checkbox() ?>

I need to wrap Terms and Coditions inside a tag with a link. How can I do this?

Upvotes: 0

Views: 2113

Answers (1)

Caleb
Caleb

Reputation: 2267

The checkbox() method takes an options array where you can override the default label:

$form->field($model, 'terms')->checkbox([
    'label' => 'I accept the <a href="/tos.html" target="_blank">Terms and Conditions</a>'
]);

Detailed Checkbox Options are in the API Documentation at http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html#checkbox()-detail

Upvotes: 5

Related Questions