Home Ask Login Register

Developers Planet

Your answer is one click away!

Sarkhan February 2016

yii2 ActiveForm field placeholder

I want to create form using yii2 ActiveForm. Here is my code:

<?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(); ?>

which generates this 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>

Everything is ok, but where is placeholder?

Answers


SohelAhmedM February 2016

Put it inside input() method as second parameter - 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>

Post Status

Asked in February 2016
Viewed 2,473 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life