jase89
jase89

Reputation: 75

Cakephp Email input validation exception

I have validation for the email input in my form but I would also like to create an exception for a string: "Not given" as some contact information do not have an email address. I know I can remove the email validation to do this but I want that validation there for new contacts. Those that do not have email addresses are some of the old contacts. So I would need an exception in order for me to add those contacts into this new system.

My current email validation in the model is as follows:

'email' => array(
        'email' => array(
            'rule' => array('email'),
            'message' => 'Please enter a valid email address',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        'uniqueEmail' => array(
            'rule'=>'isUnique',
            'message' => 'This email has already been added'
        ),
    )

How do I implement this exception and where?

Any help would be great. Thanks!!

Upvotes: 0

Views: 3110

Answers (1)

Dunhamzzz
Dunhamzzz

Reputation: 14798

Just uncomment that 'allowEmpty' => false line and change it to true, this will permit the email filled to be submitted as an empty string.

Upvotes: 1

Related Questions