Yii Framework Forum: How to find if error is set in form - Yii Framework Forum

Jump to content

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

How to find if error is set in form Rate Topic: -----

#1 User is offline   the5threvolution 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-April 10

Posted 27 April 2010 - 04:27 PM

Hello,

I've been looking at the API and searched the forum several times, but couldn't find a solution for this.

In view files, when I display errors I use

<?php $form->error($model, "id"); ?>

This displays an error message if error is set by the Controller $this->addError("id", "This is an error");.

Is there a way for me to see if there's an error with certain name?

For example, in my login, I have a field which is "active" to see if the user is activated or not (through email address confirmation). And if the user is not activated, I display an error message $this->addError("activate", "This user account is not activated."). But in view files, I want to check if error has been set for "activate", and display additional messages like this.

<?php if($form->ErrorExists($model,"activate") === true) {
echo "In order to re-send an email, press here".someurlhelperfunction."or submit another valid email address here".(display form using form helpers, etc.;
}
?>

I've thought about doing something like
if($form->error($model,"activate") contains "this user account is not activated"...)
or
$this->addError("activate", $string which contains all the information, including form);

but they both seem not as clean, and second option definitely does not separate view from controller.

Thank you very much for your help!
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 28 April 2010 - 12:55 AM

The only thing i can think of is CModel::hasErrors() : http://www.yiiframew...asErrors-detail
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
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