如何在yii表单按钮提交中添加一个类

时间:2012-11-09 06:10:14

标签: html css codeigniter yii

这是表单的代码。我想为提交按钮添加一个类,并为所有文本字段添加内联样式。我怎么能这样做?

例如在视图源中看起来像这样 我想像这样编辑

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'login-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <div class="row">
        <?php echo $form->labelEx($model,'username'); ?>
        <?php echo $form->textField($model,'username'); ?>
        <?php echo $form->error($model,'username'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'password'); ?>
        <?php echo $form->passwordField($model,'password'); ?>
        <?php echo $form->error($model,'password'); ?>
        <p class="hint">
            Hint: You may login with <kbd>demo</kbd>/<kbd>demo</kbd> or <kbd>admin</kbd>/<kbd>admin</kbd>.
        </p>
    </div>

    <div class="row rememberMe">
        <?php echo $form->checkBox($model,'rememberMe'); ?>
        <?php echo $form->label($model,'rememberMe'); ?>
        <?php echo $form->error($model,'rememberMe'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Login'); ?>
    </div>

<?php $this->endWidget(); ?>
</div><!-- form -->

2 个答案:

答案 0 :(得分:19)

尝试阅读手册或文档,或参阅示例

<?php echo $form->textField($model,'username', array('class' => 'myText', 'style' => 'width: 320px; border-radius: 10px;')); ?>

<?php echo CHtml::submitButton('Login', array('class' => 'submitClass', 'style' => 'width: 120px; border-radius: 10px;')); ?>

http://www.yiiframework.com/doc/api/1.1/CHtml#submitButton-detail

答案 1 :(得分:1)

非常简单只需添加一个数组,在其中可以放入任何html属性

<?php echo $form->textField($model,'username',array('class'=>'your class name','id'=>'Any Id You want to insert')); ?>