Hide label for input field

▼魔方 西西 提交于 2019-12-03 04:19:22

Ok, I found the solution.

<?= $form->field($model, 'sample_text')->textArea()->label(false) ?>

Or you can modify template value for particular field and remove {label} part from it. I.e.:

<p><?= $form->field($page, 'image', [
    'template' => '<div class=\"\">{input}</div><div class=\"\">{error}</div>'
])->fileInput() ?></p>
Er Amit Kumar Dubey
<?= $form->field($model, 'password', [
    'inputOptions'=>[
        'class'=>'form-control',
        'placeholder'=>'Password'
    ]
])->passwordInput()->label(false); ?>
<?= $sffForm->field($sffModel, 'url_keywords', ['enableLabel' => false])->textInput(['placeholder' => 'URL / keywords']) ?>

At time of writing after digging into the core code, I have found this to be the best solution to hide the label and prevent rendering the full field template with errors etc. for hiddenInput.

<?=
$form->field($model, 'address_uuid', [
    'template' => '{input}',
    'options' => ['tag' => false]
])->hiddenInput([
    'readonly' => true,
])->label(false)
?>

You can disable label, while creating form field class

$form->field($model, 'email', [
 'inputOptions' => [
    'enableLabel' => false,
  ]
 ])   

The best way to hide the label in form input field, is to pass empty value to array on 'attributeLabels()' function in the model.

i.e you have input filed name 'client_name', so on the 'attributeLabels()' function's return array pass the empty string as array value

public function attributeLabels()
{
    return [

        'id' => 'ID',
        'gender' => 'Gender',
        'client_name' => '',
        .
        .
        .
          ]
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!