In this post I will show an example of how apply the unique validation rule in CakePHP 1.2. It’s very important to do in some cases, like saving users. You must make sure that the username is unique in your system. Lets see how it works:
var $validate = array(
'username' => array(
'rule' => array('isUnique'),
'message' => 'Username already in use.'
)
);
I wrote a custom function to validate it, but thanks to Dia now I know the built-in validation rule.

October 19th, 2008 09:05
CakePHP 1.2 has a built-in unique validation rule :
var $validate = array( ‘myField’ => array( ‘rule’ => ‘isUnique’, ‘message’ => ‘data already exists’ ));
October 19th, 2008 12:04
Thanks for the information, I didn’t see this rule. But I already fixed the post to use it. It’s better then custom functions.
November 7th, 2008 14:57
it´s a super code!
onde eu posso pegar a “tag cloud”? muito bem sacada…
pode mandar pro email.
até mais pessoal. congratulations!
June 30th, 2009 19:01
Cool thnks!!
September 14th, 2009 07:29
But what if you need unique validation for multiple fields? For example, a comment rating system in which a user is allowed only one vote, so a unique key is set for user_id and comment_id.
March 16th, 2010 17:39
Thanks a lot! It’s very useful for version 1.2
June 19th, 2010 22:45
This is a good article, I discovered your blog page checking bing for a related topic and arrived to this. I couldnt get to much additional details on this article, so it was wonderful to locate this one. I will likely end up being returning to look at some other posts that you have another time.
February 20th, 2011 11:11
Dear friend
How can mange edit for username
June 17th, 2011 04:53
[...] Unique validation rule in CakePHP 1.2 Relaterade inlägg :jquery form validation with cakephp model validation10 Useful jQuery Form Validation Techniques and TutorialsMultiple Validation Sets in CakePHP 1.2 – Snook.ca#8958 (Optimize rewrite rule generation) – WordPress TracjQuery autocomplete Helper | The Bakery, Everything CakePHPBy Blogsdna [...]