2016-02-06 6 views
8

Ich möchte mit yii2 ActiveForm Formular erstellen. Hier ist mein Code:yii2 ActiveForm Feld Platzhalter

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

, die diesen HTML erzeugt:

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

Alles ist in Ordnung, aber wo ist Platzhalter?

Antwort

14

es hineingelegt input() Methode als zweiten 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> 
+4

Es kann auch in 'textInput' gestellt werden:' ...) -> textinput ([ 'Platzhalter' => "Geben Sie Ihre E-Mail" ]) ' – Soli

+0

Ja stimmt. Sie können die Antwort bearbeiten und Ihre Notiz hinzufügen (besser mit Verweis). Es ist relevant. – SohelAhmedM