CodeIgniter Forums
Form validation: how to use is_unique(table.field1 + table.field2) ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form validation: how to use is_unique(table.field1 + table.field2) ? (/showthread.php?tid=51352)



Form validation: how to use is_unique(table.field1 + table.field2) ? - El Forum - 04-30-2012

[eluser]Genki1[/eluser]
Question:
When validating a form, can the IS_UNIQUE() rule validate that a combination of two fields is unique in the table?

Scenario:
Each user has a list of words. I want to know if the word to be inserted is unique to that user.

Table: users_words
id
word
user_id

Example:
Is the word "happy" unique to user ID #1?

Of course, I can write this simple validation routine, but it'd be nice if the functionality is already built-in.




Form validation: how to use is_unique(table.field1 + table.field2) ? - El Forum - 04-30-2012

[eluser]Aken[/eluser]
Not already built in - is_unique() only checks if the string is unique to a column in a table - it doesn't narrow it down by another column at all. It's on you to add that functionality Smile


Form validation: how to use is_unique(table.field1 + table.field2) ? - El Forum - 04-30-2012

[eluser]Stefan Hueg[/eluser]
[quote author="Aken" date="1335830891"]... It's on you to add that functionality Smile[/quote]

...by extending the form_validation class or writing your own callback-function Smile