Reputation: 54949
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');
}
Upvotes: 1
Views: 414
Reputation: 2379
Hi you who's asking
If you want to show error-message that return from UserModel's validate
So you can add line code bellow after input form password
<?php
if ($this->Form->isFieldError('password')) {
echo $this->Form->error('password', array('class' => 'error'));
?>
and if you want to show error-message that set by method setFlash
you must redirect page and then use $this->Session->flash('flash-name') in page you want to show it
<?php
//in UsersController
$this->Session->setFlash('message here', 'flash-name');
//in view
echo $this->Session->flash('flash-name');
?>
Good luck!
Upvotes: 1
Reputation: 6571
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.
Upvotes: 2
Reputation: 4604
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');
Upvotes: 3