Re: need some help in understanding error messages

2007-08-24 Thread rtanz

i think there might have been some syntax errors so i fixed it as
follows, however it is still not working. any help?

function beforeValidate() {
// for add -there is no id
if (!isset($this-data['User']['id'])  !empty($this-
data['User']['name'])
 $this-hasAny(User.name=$this-data['User']['name']))
{
   $this-invalidate('name_unique');
}

 // for edit - there is id
if (isset($this-data['User']['id'])  !empty($this-
data['User']['name'])
  $this-findCount(User.name = $this-data['User']
['name'])) {
$this-invalidate('name_unique');
}
return true;
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: need some help in understanding error messages

2007-08-23 Thread housebolt

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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: need some help in understanding error messages

2007-08-23 Thread rtanz

but what if i have more than one error? am i correct in that you can
have only one set flash message?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: need some help in understanding error messages

2007-08-23 Thread majna

Model:
function beforeValidate()
{
# for add -there is no id
if (!isset($this-data[$this-name]['id'])  !empty($this-
data[$this-name]['name']) $this-hasAny(User.name='{$this-
data['User']['name']}' ) )
{
$this-invalidate('name_unique');
}
# for edit - there is id
if (isset($this-data[$this-name]['id'])  !empty($this-
data[$this-name]['name'])  $this-findCount(User.name = '{$this-
data[$this-name]['name']}' )
{
$this-invalidate('name_unique');
}

return true;
}

View:
?php echo $html-tagErrorMsg('User/username', 'Please enter the
Username.');?
?php echo $html-tagErrorMsg('User/name_unique', 'Username
exists...');?



On Aug 23, 10:49 pm, rtanz [EMAIL PROTECTED] wrote:
 but what if i have more than one error? am i correct in that you can
 have only one set flash message?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---