views:

34

answers:

2
+1  Q: 

Cakephp Validation

I am using an Account Controller which doesnt have its own table but uses User Model.

All works fine except - when I validate any form. It says validation fails (when I try to fail the validation to check) but doesnt throw the error below the field

View

<?php echo $this->Form->input('id'); ?>
              <label for="UserPassword">New Password:</label>
              <?php echo $this->Form->text('password', array('type' => 'password', 'value' => 'harsha')); ?><em>Password must be min 6 characters.</em> <?php echo $form->error('password'); ?>

Controller Action

            if($this->User->saveField('password', $this->data['User']['password'], array('validate' => 'first'))) {
                $this->Session->setFlash('Password has been changed.', 'flash-success');
            } else {
                $this->Session->setFlash('There was some problem with our system. Please try after some time.', 'flash-warning');
            }
+2  A: 

Try debug()ing the contents of $this->validationErrors in your view, as well as $this->data in your controller just after a form submission. This should give you a lot more information to work from.

I suspect that your problem is Cake is building form inputs based on the wrong model -- building form fields for Account.id and Account.password instead of User.id and User.password. This is because FormHelper takes its default model from the controller/view it's invoked from, which in your case appears AccountsController.

In order to generate the User.id and User.password fields your controller's submission handling expects, you'll need to prepend User. in your FormHelper calls. Thus:

$this->Form->input('User.id');
$this->Form->text('User.password');
Daniel Wright
+2  A: 

Have you tried:

echo $session->flash();

Note that whatever the manual says, it returns, not echoes. I logged this a while back and it has been changed in the 1.3 manual, but not the 1.2.

Leo