Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add class to Form in Yii framework?

Tags:

css

forms

class

yii

I have a form in Yii, and I want to add a class to the form :

<form class="subscribe_form" action="#" method="post">

I tried this but it's not working :

<?php $form=$this->beginWidget('CActiveForm', array(
                                                'class'=>'subscribe_form',
                        'id'=>'mail-list-addmail-form',
                        'enableAjaxValidation'=>false
                    )); ?>

Thanks for helping me!.

like image 338
deltascience Avatar asked May 26 '13 22:05

deltascience


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.


1 Answers

You need to pass an htmlOptions property, like this:

<?php $form=$this->beginWidget('CActiveForm', array(
                        'id'=>'mail-list-addmail-form',
                        'enableAjaxValidation'=>false,
                        'htmlOptions'=>array(
                          'class'=>'subscribe_form',
                        )
                    )); ?>

from http://www.yiiframework.com/doc/api/1.1/CActiveForm#htmlOptions-detail

like image 129
flyingjamus Avatar answered Oct 17 '22 03:10

flyingjamus