0

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.

1
  • which version u r using? 1.2 or 1.3? is it throwing any error??
    – RSK
    Dec 1, 2010 at 15:56

1 Answer 1

1

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.

4
  • You are right. It is necessary to remove required parameter. Thanks RabidFire. Dec 1, 2010 at 16:19
  • >On the other hand, the form that you're using in the secret area probably does not have an email field. That is correct too. Dec 1, 2010 at 16:23
  • I resolved it like this pastebin.com/WgeLhqXB now I have single controller validation in signup. Dec 1, 2010 at 16:41
  • The problem with the way you've resolved it is: If you have a form where a user can change his email address, the validation is bypassed and the user can enter something that does not look like an email address.
    – RabidFire
    Dec 1, 2010 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.