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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13303006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:47:53  来源:igfitidea点击:

How to add a class in yii form button submit

htmlcsscodeigniteryii

提问by I'm Geeker

This is a code for a form. I want to add a class for submit button and add a inline style for all text fields. How can I do this one?

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

for example in view source look like this I want to edit like this

例如在查看源看起来像这样我想像这样编辑

<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 -->

回答by Sergey

Try read manual or docs, or see examples

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

<?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

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

回答by Ibrahim Khan

very simple just add an array,in it you can put any html attribute in it

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

Like

喜欢

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