Welcome Guest, Not a member yet? Register   Sign In
check if a value already exists in database
#9

(This post was last modified: 04-09-2016, 04:30 AM by Tecvid.)

(01-01-2016, 09:30 PM)shanavas_m Wrote:
How to check if a value already exists in database using built in form validation methods ?

Thanks in advanceĀ 

yeah, i am late for a reply, but i have the simplest way to check if a value already exists, just extend form validation class by MY_Form_validation like this:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Form_validation extends CI_Form_validation {

    public function 
is_exists($str$field)
    {
        return 
$this->is_unique($str$field) === FALSE;
    }



now, create form_validation_lang.php file in your language directory and:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$lang['form_validation_is_exists'] = 'The {field} field is already exists.'

that's all, now u can use in this way Smile

PHP Code:
$rules = array(
    array(
        
'field' => 'email',
        
'label' => 'lang:email',
        
'rules' => 'required|is_exists[users.email]'
    
)
); 
Reply


Messages In This Thread
RE: check if a value already exists in database - by Tecvid - 04-09-2016, 04:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB