【问题标题】:yii2 ActiveForm field placeholderyii2 ActiveForm 字段占位符
【发布时间】:2016-02-06 19:35:30
【问题描述】:

我想使用 yii2 ActiveForm 创建表单。这是我的代码:

<?php
$form = \yii\widgets\ActiveForm::begin([
    'options' => [
        'class' => 'form-inline'
        ]
]);
?>
<div class="form-group">
     <label class="sr-only" for="example">Email</label>
     <?php echo $form->field($model, 'email', [
           'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
     ])->textInput(['placeholder' => "Enter Your Email"])->input('email')->label(false); ?>
</div>


<button type="submit" class="subscr-btn btn btn-primary btn-fill">Join</button>
<?php \yii\widgets\ActiveForm::end(); ?>

生成这个 html:

<form id="w0" class="form-inline" action="/example" method="post">
<div class="form-group">
    <label class="sr-only" for="exampleInputEmail2">Email address</label>
    <div class="form-group field-subscriber-email required">
        <input type="email" id="subscriber-email" class="form-control transparent" name="Subscriber[email]"
               autofocus="autofocus">
        <div class="help-block"></div>
    </div>
</div>
<button type="submit" class="subscr-btn btn btn-primary btn-fill">Join</button>

一切正常,但占位符在哪里?

【问题讨论】:

    标签: php yii2 field


    【解决方案1】:

    把它放在input()方法中作为第二个参数-reference

    <div class="form-group">
         <label class="sr-only" for="example">Email</label>
         <?php echo $form->field($model, 'email', [
               'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
         ])->textInput()->input('email', ['placeholder' => "Enter Your Email"])->label(false); ?>
    </div>
    

    【讨论】:

    • 也可以放入textInput:...)-&gt;textInput(['placeholder' =&gt; "Enter Your Email"])
    • 是的。您可以编辑答案并添加您的注释(参考更好)。这是相关的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2019-08-17
    • 2017-01-25
    • 1970-01-01
    相关资源
    最近更新 更多