2016-02-06 7 views
8

yii2 ActiveFormを使用してフォームを作成したいと思います。ここでは私のコードは次のとおりです。yii2 ActiveFormフィールドプレースホルダー

このHTMLを生成
<?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(); ?> 

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

すべてがOKですが、どこプレースホルダがありますか?

答えて

14

2番目のパラメータとしてinput()メソッドの内部でそれを入れて - それはまたtextInput` `に入れることができる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> 
+4

:' ...) - >にtextInput([ 'プレースホルダ' => "あなたのメールアドレスを入力して" ]) ' – Soli

+0

はい。答えを編集してメモを追加することができます(参考にしてください)。これは関連しています。 – SohelAhmedM