27

This is the activeform field. I would like to know how to add a css class to it.

<?= $form->field($model, 'url')->label(false); ?>
Jitendra Pawar
  • 1,285
  • 15
  • 27
Omar Tariq
  • 7,536
  • 10
  • 38
  • 57

2 Answers2

40

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

Mihai P.
  • 9,307
  • 3
  • 38
  • 49
3
<?= $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)?>
newbdeveloper
  • 394
  • 3
  • 11