Writing your own validators
Yii provides a good set of built-in form validators that cover the most typical of developer's needs and are highly configurable. However, in some cases, the developer may face a need to create a custom validator.
A good example would be the website ownership validation. For a few of their services, Google requires you to upload a file with the name and content specified to your website, and then checks if it is there. We will do the same.
There are two ways to achieve it; you can use a class method as a validator, or the second way is to create a separate class.
Getting ready
Create a new application using yiic webapp as described in the official guide.
How to do it...
We will start with the class method approach. First, we need to implement a form model. So, create
protected/models/SiteConfirmation.phpas follows:<?php class SiteConfirmation extends CFormModel { public $url; public function rules() { return array( array('url', 'confirm...