Hide label for input field

前端 未结 7 869
孤街浪徒
孤街浪徒 2021-02-06 23:04

I am trying to hide the label for a specific field in _form.php without success.

I have tried couple of variation like, but none is working:



        
相关标签:
7条回答
  • 2021-02-06 23:27

    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>
    
    0 讨论(0)
  • 2021-02-06 23:33

    Ok, I found the solution.

    <?= $form->field($model, 'sample_text')->textArea()->label(false) ?>
    
    0 讨论(0)
  • 2021-02-06 23:39

    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)
    ?>
    
    0 讨论(0)
  • 2021-02-06 23:43

    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' => '',
            .
            .
            .
              ]
     }
    
    0 讨论(0)
  • 2021-02-06 23:44
    <?= $sffForm->field($sffModel, 'url_keywords', ['enableLabel' => false])->textInput(['placeholder' => 'URL / keywords']) ?>
    
    0 讨论(0)
  • 2021-02-06 23:46

    You can disable label, while creating form field class

    $form->field($model, 'email', [
     'inputOptions' => [
        'enableLabel' => false,
      ]
     ])   
    
    0 讨论(0)
提交回复
热议问题