0
votes

I prepare some registration form (the simplest) and in my Model i prepare some validation for email field:

'email' => array(
    'mail' => array(  
        'rule' => array('email', true),  
        'required' => false,  
        'message' => 'Not correct e-mail!'),  
    'unique' => array(  
        'rule' => 'isUnique',  
        'message' => 'E-mail was registered!'))

But the rule isUnique doesn't work.
Addition i change in MySQL field email to unique, but still doesn't work.
I use CakePHP 2.3.7


Problem is when we use Translate behavior with model.

The query:

SELECT COUNT(DISTINCT(`User`.`id`)) AS count FROM `sometable`.`users` AS `User` INNER JOIN `sometable`.`i18n` AS `I18nModel` ON (`User`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'User' AND `I18nModel`.`locale` = 'pl') WHERE `User`.`email` = '[email protected]'

Field email isn't translated.

2
isUnique always is valid, even if the e-mail is registered - kicaj
Yes, rule ('email', true) works good:/ - kicaj
Check the sql log - If there is no query for select count(*) from users where email = "text you entered" - it's likely the rule is not defined correctly. - AD7six
@AD7six Problem is when we use Translate with model and i show query bellow - kicaj
I don't know what you wish to say with that. - AD7six

2 Answers

1
votes

Try this.

array(
    'email' => array(
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Provide an email address'
        ),
        'validEmailRule' => array(
            'rule' => array('email'),
            'message' => 'Invalid email address'
        ),
        'uniqueEmailRule' => array(
            'rule' => 'isUnique',
            'message' => 'Email already registered'
        )
    )
);
1
votes

I copied your code and pasted it in my Model and it just worked fine!!! I don't think there is any error in it. I just added semicolon after your code. Here is the code that I have checked:

'email' => array(
            'mail' => array(
                'rule' => array('email', true),
                'required' => false,
                'message' => 'Not correct e-mail!'),
            'unique' => array(
                'rule' => 'isUnique',
                'message' => 'E-mail was registered!')), 

I think there would be some other error!!