In your view you have only Administration model fields, no Credit
model fields (I assume from your example) - so the form helper don't
know where to place any invalid field information from the Credit
model.
Try either to use Credit model fields, or maybe change this:
[change]
$form->error('credits')
to
$form->error('Credit.credits');
[/change]
Haven't tried it, so no idea if it will work!
Enjoy,
John
On Feb 19, 1:17 am, Cedric <[email protected]> wrote:
> Hi I am developing an application for my uni project but I am having
> trouble with validation error message doesn't show if the validation
> error is in a different model
>
> So where my validation is in the Credit Model but in an Administration
> view/controller I save to the Credit Model
>
> so my credit model is like so
>
> var $validate = array(
> 'credits'=>array(
> 'rule' => array('comparison', '>',0),
> 'message' => 'credit has to be a number and bigger than 0'
> )
> )
>
> and in my Administration controller I have the following
>
> function add() {
> // get the user id value from the form
> $userId = $this->data['Administration']['user_id'];
> // get the user's active credit
> $credit = $this->Credit->find('first', array(
> // return only this model (no associated models)
> 'recursive' => -1,
> 'conditions' => array('user_id' => $userId, 'paid_out' => 0)
> ));
> $numCredits = $this->data['Administration']['credits'];
> $credit['Credit']['credits'] = $credit['Credit']['credits'] +
> $numCredits;
>
> $this->Credit->set(array('credits' => $numCredits));
>
> if ($this->Credit->validates()){
>
> //if($this->Credit->save($credit)){
>
> $this->Credit->save($credit);
> // let the admin know the credits have been added
> $this->flash('You have now added ' . $numCredits . '
> credits to the
> user\'s account', array('action' => 'index'), '5');
> } else
> {
> //loads addCredits
> $this->addCredits();
> //reapply previous information from view
> $this->render('addCredits');
> }
> }
>
> I also have the following in the administration view
>
> <div class="fieldData">
> <?php echo $form->error('credits'); ?>
> <?php echo $form->input('credits', array('size' => '2', 'label'
> => false));?>
> </div>
>
> Can someone please give me some advice I been looking at this for like
> hours and can't figure out why error message doesn't show
>
> Many thanks
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en