2016-02-06 4 views
8

Я хочу создать форму, используя yii2 ActiveForm. Вот мой код: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> 

Все это хорошо, но где-заполнитель?

ответ

14

Положите его внутри 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> 
+4

Он также может быть введен в 'textInput':' ...) -> TextInput ([ 'заполнитель' => "Введите Ваш E-mail" ]) ' – Soli

+0

Да, правда. Вы можете отредактировать ответ и добавить свою заметку (лучше со ссылкой). Это актуально. – SohelAhmedM

Смежные вопросы