2016-02-06 40 views
8

Tôi muốn tạo biểu mẫu bằng cách sử dụng yii2 ActiveForm. Đây là mã của tôi:yii2 Trình giữ chỗ trường 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(); ?> 

mà tạo ra html này:

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

Mọi thứ đều ok, nhưng mà là giữ chỗ?

Trả lời

14

Đặt nó bên trong phương pháp input() như tham số thứ hai - 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

Nó cũng có thể được đặt trong 'textInput':' ...) -> textinput ([ 'giữ chỗ' => "Nhập Email của bạn" ]) ' – Soli

+0

Có đúng. Bạn có thể chỉnh sửa câu trả lời và thêm ghi chú của mình (tốt hơn với tham chiếu). Nó có liên quan. – SohelAhmedM

Các vấn đề liên quan