The easiest way to do this is by using $this->Session-
>setFlash('Username already exists'); in your controller. The error
message will show up at the top of the page or wherever you put "if
($session->check('Message.flash')) $session->flash();" in your layout.

On Aug 23, 7:33 am, rtanz <[EMAIL PROTECTED]> wrote:
> hi right now i have baked a model with an add and edit view as
> automatically generated by cake. So now if I make any errors when
> saving (as determined by the $validate conditions below) I will get
> the values of the tagErrorMsg as set in the view. Now I also made a
> beforeSave function that checks whether a user with that username
> exists already, and in that case I would like to output a different
> message saying that 'Username already exists' instead of 'Please enter
> the Username'. How can i do this? thanks
>
> class User extends AppModel
> {
>     var $name = 'User';
>         var $hasMany = array('Membership'=>array('dependent'=>true));
>
>         var $validate = array(
>       'username' => '/[a-z0-9\_\-]{3,}$/i',
>       'password' => VALID_NOT_EMPTY,
>       'email' => VALID_EMAIL,
>    );
>
>         function beforeSave() {
>                 $user = $this->data['User']['username'];
>                 $conditions = array("User.username"=>"$user");
>                 if ($this->find($conditions)) {
>                         return false;
>                 }
>                 else return true;
>         }
>
> }
>
> <?php echo $html->tagErrorMsg('User/username', 'Please enter the
> Username.');?>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to