Welcome Guest, Not a member yet? Register   Sign In
MongoDB + Form_Validation Method is_unique()
#1

[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;

    }

}


Messages In This Thread
MongoDB + Form_Validation Method is_unique() - by El Forum - 09-03-2012, 11:59 PM
MongoDB + Form_Validation Method is_unique() - by El Forum - 09-20-2012, 02:08 PM
MongoDB + Form_Validation Method is_unique() - by El Forum - 09-20-2012, 03:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB