Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:45:25+00:00 2026-06-06T11:45:25+00:00

When we use CactiveForm Widget like this: <?php echo $form->labelEx($model,’name’); ?> <?php echo $form->textField($model,’name’);

  • 0

When we use CactiveForm Widget like this:

<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>

We get validation messages but, the input field himself our the textfield, don’t get any class.

I wish to, when Yii validates, a class appears on the input field so that it could render highlighted.

CHtml::activeTextField actually does this:

<?php echo CHtml::activeLabel($model,'name'); ?>
<?php echo CHtml::activeTextField($model,'name') ?>

Any way to do this using CActiveForm ?

Added:

$form=$this->beginWidget('CActiveForm', array(
    'id'=>'event-form',
        'enableClientValidation' => true,
        'clientOptions'=>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:45:27+00:00Added an answer on June 6, 2026 at 11:45 am

    For the default error class to be attached you need to have the structure of your form as it is in the default auto generated forms, something like this:

    <div class="form">
      <?php $form=$this->beginWidget('CActiveForm', array(
        ...
      )); ?>
    
        <div class="row">
            <?php echo $form->labelEx($model,'name'); ?>
            <?php echo $form->textField($model,'name'); ?>
            <?php echo $form->error($model,'name'); ?>
        </div>
        ...
    </div>
    

    Edit: Meaning you need an inputContainer for each input field, because that’s how the default css and default implementation of jquery.activeform.js is. To change this behavior we can simply add another css rule to the default form.css file, which by default adds errors only to divs inside div.form.

    /*
     default css
    */
    div.form div.error input,
    div.form div.error textarea,
    div.form div.error select,
    div.form input.error,
    div.form textarea.error,
    div.form select.error
    {
        background: #FEE;
        border-color: #C00;
    }
    

    So you can change that to your liking, but minimum required will be :

    div.error input, div.error textarea, div.error select {/* styles */}
    

    Incase the above doesn’t work and you want to assign error class to input elements individually then you can use the afterValidate and afterValidateAttribute callbacks of CActiveForm’s clientOptions, where you’ll need to add the error css class to the input, and also have a css rule to match such inputs:

    input.error, textarea.error, select.error {/*styles*/}
    

    Incase you use some form of client validation, like you have done in beforeValidate, you’ll need to addClass('error'); to your inputs, with the above css in place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
use the [] symbol in the name of the form field you are submitting
Use of Unassigned local variable 'model'. Is what error message I'm getting. Its right
Use Html element SELECT in aspx page like: <SELECT id=MySelection name=MySelection runat=server DataValueField=ID DataTextField=Name></SELECT>
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I
use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub {
use strict; use Time::HiRes qw[gettimeofday tv_interval]; my $start_index = int(rand(50))+100;#this value is arbitrary for
use this code, in the Preferences activity, to know when the reset preference has
On my page I'm using a form which on submit should get some extra
Use OPENXML to get dt element in MSSQL 2005. How can I get xmlns:dt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.