Jump to content


is_unique function checking in edit page

is_unique is_unique in edit page

  • Please log in to reply
2 replies to this topic

#1 manojdamkondwar

manojdamkondwar

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 09 April 2014 - 04:18 PM

Hi,

I have question,

 

I am trying to add unique value in my table filed it's working with grocery crud 'is_unique' function, but problem facing with edit page.

When I am trying to edit any value it's checking and getting error must need unique value if value is in table only one also..

plz any one can help me..



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 09 April 2014 - 08:13 PM

Yes this is a common programing paradigm u need to understand my brother..

to manage the same u need to set a custom callback to the rule..

 

here is the sample you can look into ..

$crud->set_rules('email', 'Email', 'required|email|callback_email_check');

......and the callback function below


function email_check($email) {
		$primary_key = $this->uri->segment(5);      // this is what u need to adjust according to yr url pattern.. 
                                                                                    //mine is deep so i set it 5. u need to do it 4 yr own needs
		$rows = $this->cModel->getAllFor('retailer_acct', 'email', $email);
		if(!empty($primary_key) && is_numeric($primary_key))
		{
			if(count($rows)>0) {
				if($rows[0]['id'] != $primary_key) {
					$this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
					return false;
				}
			}
			return true;
		} else {
			if(count($rows)>0) {
				$this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
				return false;
			} else {
				return true;
			}
		}
	}


#3 xheradon

xheradon

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts
  • LocationSpain

Posted 01 March 2017 - 02:03 PM

 

Yes this is a common programing paradigm u need to understand my brother..

to manage the same u need to set a custom callback to the rule..

 

here is the sample you can look into ..

$crud->set_rules('email', 'Email', 'required|email|callback_email_check');

......and the callback function below

function email_check($email) {
		$primary_key = $this->uri->segment(5);      // this is what u need to adjust according to yr url pattern.. 
                                                                                    //mine is deep so i set it 5. u need to do it 4 yr own needs
		$rows = $this->cModel->getAllFor('retailer_acct', 'email', $email);
		if(!empty($primary_key) && is_numeric($primary_key))
		{
			if(count($rows)>0) {
				if($rows[0]['id'] != $primary_key) {
					$this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
					return false;
				}
			}
			return true;
		} else {
			if(count($rows)>0) {
				$this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
				return false;
			} else {
				return true;
			}
		}
	}

 

I have

 

$crud->set_rules('email', 'email', 'required|valid_email|callback_email_check');

 

and 

public function email_check($email) {
        $primary_key = $this->uri->segment(4);     
        dump($email);
        dump($primary_key);
        $this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
        $rows = $this->cModel->getAllFor('retailer_acct', 'email', $email);
        if(!empty($primary_key) && is_numeric($primary_key))
        {
            if(count($rows)>0) {
                if($rows[0]['id'] != $primary_key) {
                    $this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
                    return false;
                }
            }
            return true;
        } else {
            if(count($rows)>0) {
                $this->form_validation->set_message('email_check', 'The email - ' . $email . ' already is assigned to some other user');
                return false;
            } else {
                return true;
            }
        }
    }

But alwayis returning FIXME('form_validation_email_check')

 

Can u help me? thanks







Also tagged with one or more of these keywords: is_unique, is_unique in edit page

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users