Yii Framework Forum: Change content of CHtml::errorSummary() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Change content of CHtml::errorSummary() Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 15 December 2009 - 07:12 AM

It currently outputs the following:

Please fix the following input errors:

Name cannot be blank.
Phone cannot be blank.


I want it to output the following:

Error: Name cannot be blank, Phone cannot be blank.


How can I do this?
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,902
  • Joined: 04-October 08
  • Location:DC, USA

Posted 15 December 2009 - 08:20 AM

http://www.yiiframew...rSummary-detail
0

#3 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 15 December 2009 - 08:25 AM

View PostGSTAR, on 15 December 2009 - 07:12 AM, said:

It currently outputs the following:

Please fix the following input errors:

Name cannot be blank.
Phone cannot be blank.


I want it to output the following:

Error: Name cannot be blank, Phone cannot be blank.


How can I do this?


Override CHtml::errorSummary() ?
0

#4 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 15 December 2009 - 08:27 AM

OK well I tried modifying header & footer values but that doesn't let me put the error "fields" on one line.
0

#5 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,902
  • Joined: 04-October 08
  • Location:DC, USA

Posted 15 December 2009 - 08:40 AM

You can use CSS to achieve that effect.
0

#6 User is offline   quantico 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 05-May 11
  • Location:Guatemala

Posted 29 November 2011 - 04:47 PM

View PostGSTAR, on 15 December 2009 - 07:12 AM, said:

It currently outputs the following:

Please fix the following input errors:

Name cannot be blank.
Phone cannot be blank.


I want it to output the following:

Error: Name cannot be blank, Phone cannot be blank.


How can I do this?


div.form.errorSummary ul li
{
display: inline;
list-style-type: none;
}


and if you want take off the header (Please fix the following input errors:) and the footer in that order


<?php echo $form->errorSummary($model,"",""); ?>



for more information check framework/web/helpers/CHtml.php file. ref: http://www.yiiframew...rSummary-detail

public static function errorSummary($model,$header=null,$footer=null,$htmlOptions=array())
{
    $content='';
    if(!is_array($model))
        $model=array($model);
    if(isset($htmlOptions['firstError']))
    {
        $firstError=$htmlOptions['firstError'];
        unset($htmlOptions['firstError']);
    }
    else
        $firstError=false;
    foreach($model as $m)
    {
        foreach($m->getErrors() as $errors)
        {
            foreach($errors as $error)
            {
                if($error!='')
                    $content.="<li>$error</li>\n";
                if($firstError)
                    break;
            }
        }
    }
    if($content!=='')
    {
        if($header===null)
            $header='<p>'.Yii::t('yii','Please fix the following input errors:').'</p>';
        if(!isset($htmlOptions['class']))
            $htmlOptions['class']=self::$errorSummaryCss;
        return self::tag('div',$htmlOptions,$header."\n<ul>\n$content</ul>".$footer);
    }
    else
        return '';
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users