开发者

CakePHP auth and validation

I have an app that uses Auth component. Logedin members can alter their data as long as I have no validation rules in users model. When I add array $validate in model logedin users cannot submit data to database.

I use one mysql table named users.

In other words this works but I don't have validation in signup view

<?php
class User extends AppModel {
var $name = 'User';
?>

But when I add validation like this:

<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
 开发者_开发百科 'email' => array(
    'email' => array('rule' => 'email','required'=>true,'message' => 'Enter proper mail')
  )
);
}
?>

validation in signup view works but users in secret area cannot enter data to database.


My guess is: This is happening because you have set required to true.

This enforces the rule that when submitted data of the User model, the email key needs to be set. Therefore, this works in your Sign Up form which obviously has the email key. On the other hand, the form that you're using in the secret area probably does not have an email field.

Just remove the "required" condition from your validation rule:

'email' => array(
    'email' => array(
        'rule' => array('email'),
        'message' => 'Please enter a valid email',
    ),
),

Let me know if this works for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜