Yii Framework Forum: test error in CActiveForm - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

test error in CActiveForm Rate Topic: -----

#1 User is offline   karim gioca 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 21-September 10

Posted 15 June 2011 - 05:17 AM

Hi every one, is there a way to put a test in the view that contain an CActiveForm ?
i mean is there a way to something like that :
if($form->hasError)
{
    echo $form->errorSummary($model);
}

i know that "hasError" is not a property in hasError, i just put it like example ;)
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 June 2011 - 05:27 AM

Why would you need this...

if you check the source of errorSummary()... you will see that it does not output anything if there are no errors...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 June 2011 - 05:32 AM

ops... the CHtml::errorSummary() does not echo anything if there are no errors...

but

the CActiveForm::errorSummary() does echo a placeholder even if there are no errors...

To test if there are errors... you can use $model->getErrors() - http://www.yiiframew...etErrors-detail
Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   karim gioca 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 21-September 10

Posted 15 June 2011 - 05:36 AM

View Postmdomba, on 15 June 2011 - 05:27 AM, said:

Why would you need this...

i need that because i want to display error message in a specefic box that contain other tags
<div class="error ">
            <a class="close" href="#"><img alt="close" title="Close this notification" src="<?php echo Yii::app()->request->baseUrl; ?>/themes/img/cross_grey_small.png"></a>
            <div>
                <?php echo $form->errorSummary($model); ?>
            </div>
</div>

and i saw that when i want to change the error summary, i can only change the css, but not the content of the error summary, so i thought that putting this specefic error message into a test and become like i suppose :
<?php if($form->hasError) : ?>
<div class="error ">
            <a class="close" href="#"><img alt="close" title="Close this notification" src="<?php echo Yii::app()->request->baseUrl; ?>/themes/img/cross_grey_small.png"></a>
            <div>
                <?php echo $form->errorSummary($model); ?>
            </div>
</div>
<?php endif; ?>


if you have an other way to display this i'll be happy to hear it ^^
0

#5 User is offline   karim gioca 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 21-September 10

Posted 15 June 2011 - 05:47 AM

View Postmdomba, on 15 June 2011 - 05:32 AM, said:

To test if there are errors... you can use $model->getErrors() - http://www.yiiframew...etErrors-detail

Yes exactly ! that's what i'm searching :) thanx !

but to develop this topic, i want to know how can i costomise the errorsummary by adding html tags ? (like the example that i give)
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 June 2011 - 06:06 AM

errorSummary() has it's fixed display...

but you can use $model->getErrors() to get the errors list... and display it anyway you want...
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   pringlized 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 11-April 11

Posted 23 June 2011 - 06:42 AM

Noodled my brain over this for an hour. I have a specific class I need to attach to the error messages. So made the process a bit stickier since empty error messages would be rendered as an empty div with a class attached. I was focused on the CActiveForm functions. Thanks mdomba!


What I got that works:
    <? if(array_key_exists('username', $model->getErrors())): ?>
        <?= $form->error($model,'username',array('class'=>'message errormsg')); ?>
    <? endif; ?>

    <? if(array_key_exists('password', $model->getErrors())): ?>
        <?= $form->error($model,'password',array('class'=>'message errormsg')); ?>
    <? endif; ?>

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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