Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add class to ActiveForm in Yii 2.0 framework?

I'd like to add a class to the form like:

<form role="form" action="/login" method="POST" class="userform">

How should I rewrite this for Yii 2.0 ActiveForm class?

The same question is for this structure inside of the form tag:

<div class="ui-grid-solo">
     <div class="ui-grid-a">
          <label for="name">Full Name</label>
          <input type="text" name="login" id="login" value="" data-clear-btn="true" data-mini="true">
          <label for="password">Password</label>
          <input type="password" name="password" id="password" value="" data-clear-btn="true" autocomplete="off" data-mini="true">
          <input type="checkbox" name="remind" id="remind" value="1">
          <label for="remind">Remember me</label>
          <br>
          <input type="submit" value="Login" onclick="this.form.submit();">
     </div>
</div>
like image 278
Павел Иванов Avatar asked Sep 08 '14 06:09

Павел Иванов


People also ask

How to add class in Active form in yii2?

You can use htmlOptions : <? php $form = ActiveForm::begin( [ 'action' => '/login', 'htmlOptions' => [ 'class' => 'userform' ] ] ); // ... add all your inputs here for example: echo $form->field($model, 'login'); ActiveForm::end(); ?>

What is active form yii2?

ActiveForm is a widget that builds an interactive HTML form for one or multiple data models. For more details and usage information on ActiveForm, see the guide article on forms.


2 Answers

In Yii2 I don't think 'htmlOptions' works. Just 'options' is correct, e.g.

<?php     $form = ActiveForm::begin(         [             'action' => '/login',             'options' => [                 'class' => 'userform'              ]         ]     );     // ... add all your inputs here for example:     echo $form->field($model, 'login');     ActiveForm::end(); ?> 
like image 172
Alec Smythe Avatar answered Oct 12 '22 18:10

Alec Smythe


To add class in ActiveForm Yii2.0. You should use options

<?php $form = ActiveForm::begin(['action' => '/login','options' => ['class' => 'userform','enctype' => 'multipart/form-data']]); ?>

Please read this link for further clarification.

like image 30
Kartz Avatar answered Oct 12 '22 18:10

Kartz