簡體   English   中英

yii2 ActiveForm字段占位符

[英]yii2 ActiveForm field placeholder

我想使用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>

一切都好,但占位符在哪里?

將它放在input()方法中作為第二個參數 - 引用

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM