How to add a class in yii form button submit

28,336

Solution 1

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

Solution 2

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

Like

<?php echo $form->textField($model,'username',array('class'=>'your class name','id'=>'Any Id You want to insert')); ?>
Share:
28,336
I'm Geeker
Author by

I'm Geeker

I'm a simple developer with cracker of coding :)

Updated on July 29, 2020

Comments

  • I'm Geeker
    I'm Geeker over 3 years

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