Yii2 - How To Add a CSS class to an ActiveForm Field

You can add it with

<?= $form->field($model, 'url')->textInput(['maxlength' => 255, 'class' => 'your class'])->label(false); ?>

As a rule you can pass html elements when telling activeField what type it should be. The default is textInput so that is why your code works, but if you want to change the input then you have to explicitly tell it the type of input.

http://www.yiiframework.com/doc-2.0/guide-input-forms.html


<?= $form->field($addWithdrawRequest, 'amount', ['options' => ['tag' => false]])->textInput(['class' => 'form-control col-lg-6 amount','required'=>true,'style' => 'background-color: #fff !important;','placeholder'=>"Enter Amount To Withdraw"])->label(false)?>

Tags:

Yii2