【问题标题】:How to add class to Form in Yii framework?Yii框架中如何给Form添加类?
【发布时间】:2013-05-21 18:36:50
【问题描述】:

我在 Yii 中有一个表单,我想在表单中添加一个类:

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

我试过了,但它不起作用:

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

谢谢你帮助我!

【问题讨论】:

    标签: css forms class yii


    【解决方案1】:

    你需要传递一个 htmlOptions 属性,像这样:

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

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

    【讨论】:

      【解决方案2】:

      htmlOptions: additional HTML attributes that should be rendered for the form tag.

      htmlOptions:一般通过所有 HTML 助手CHtmlCActiveForm,您可以在此属性中设置自定义 HTML 选项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-08
        • 1970-01-01
        相关资源
        最近更新 更多