Question

I'm using CakePHP 2.3.8 and the email rule validates that the email has a valid host name or so. This is great, I like this feature, but it does not make things easy when testing on a local server, specially if it's offline.

Is there anyway to disable this very quick? A config variable maybe?

EDIT: Not going model by model changing the rule variable, but a global config variable.

Was it helpful?

Solution

You just need to remove second arguments from rule-- Like you defined as

'rule' => array('email', true)

This should be as-

'rule' => array('email')

after edit on question

You can do this by dynamic validation. But the easy approach will be unset email validation thus you are on development environment..

AppModel.php

public function beforeValidate(){
                   if$this->validate['email'](){
                     unset($this->validate['email']);
                   }
             // now, If you really need to check email add dynamic rule for email field here.
}   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top