[eluser]sweetD[/eluser]
So I wanted to use the is_unique rule in my form validations, but since I'm using Alex Bilbie's Mongo Library, I needed to extend From_validation from the core. Check out what I did below, just wanted to make a quick contribution. I want it to check if lowercase also so I need to add that in there. For example right now if you enter "Peter" and is_unique "peter" it will not be the same and peter lowercase will be allowed even though "Peter" exists.
Code:
array(
'field' => 'picture_tag',
'label' => 'Picture Tag',
'rules' => 'trim|required|min_length[3]|max_length[32]|alpha_numeric|is_unique[users/personal_information.picture_tag]'
)
Code:
<php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
public function __construct()
{
parent::__construct();
}
public function is_unique($str,$field)
{
list($collection,$field) = explode('/', $field);
$q = $this->CI->mongo_db->limit(1)->where(array($field => $str))->count($collection);
return $q === 0;
}
}