Anyway To Log Form Validation Errors?

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?

in your model for login you can add:

	public  function onAfterValidate($event)






		return true;


u main config,in log, you can add this route, so you will get email on error








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

yes, that’s the file.

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.

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.

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




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


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.