Yii Framework Forum: Anyway To Log Form Validation Errors? - Yii Framework Forum

Jump to content

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

Anyway To Log Form Validation Errors? Rate Topic: -----

#1 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 28 January 2013 - 01:40 PM

I am taking over a project that another developer finished. It was created using Yii, which I'm not very familiar with.

I would like to be able to see when users submitting forms on my site run into any validation errors. Is there anyway to easily log this information so I can see any errors users receive, along with the data they entered which triggered the error?
0

#2 User is offline   nermin.i 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 09-January 13

Posted 28 January 2013 - 03:52 PM

in your model for login you can add:

	public  function onAfterValidate($event)
	{
		if($this->hasErrors())
		{
			Yii::log(CVarDumper::dumpAsString($this->getErrors()),'error','application.model.login');
		}
		return true;
	}


u main config,in log, you can add this route, so you will get email on error
 array(
	'class'=>'CEmailLogRoute',
	'levels'=>'error',
         'categories'=>'application.model.login',
	'emails'=>'your@email',
),

0

#3 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 28 January 2013 - 04:24 PM

Thanks!

For the second part, did you mean in /protected/config/main.php?
0

#4 User is offline   Hesam 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 12-November 12
  • Location:Toronto

Posted 28 January 2013 - 06:08 PM

View Postmayonaise, on 28 January 2013 - 04:24 PM, said:

Thanks!

For the second part, did you mean in /protected/config/main.php?


yes, that's the file.
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 29 January 2013 - 03:40 PM

Minor note: I'd not override onAfterValidate() but afterValidate(). The latter was built for this purpose. If you don't do that, your event may not trigger correctly anymore. This could matter if you e.g. attach a behavior which tries to attach another handler to this event. And you should call parent::beforeValidate() from your override method.
0

#6 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 29 January 2013 - 03:51 PM

Hi Mike,

I'm not really familiar with Yii, so I'm not sure what you mean.

Can you please give me an example of how to make those changes? I tried making the updates that nermin,i suggested, but I never received any emails.
0

#7 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 30 January 2013 - 03:09 AM

Maybe try to log into a file first (just to make sure, it's not an email transport problem):


array(
        'class'=>'CFileLogRoute',
),



I also recommend to read the guide section about logging because you should learn to help yourself :)

http://www.yiiframew.../topics.logging
0

#8 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 30 January 2013 - 12:58 PM

I was able to get the logging to work to a file, but not email. That's good enough.

I've read through the docs on logging, but I cannot seem to figure out how to make it show an error when a JavaScript form error occurs. Is this possible? The only thing I could get to work is logging server-side errors or record when an ajax request is made, but I can't see the errors that the visitor gets when trying to fill out a form.
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