⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Validate if data already exist in the database



chickenstealers
  • profile picture
  • Member

Posted 26 January 2017 - 07:45 AM

Hey i'm new to grocery crud,

 

I want to implement validation data on my add form

the form had multiple field :

company, address, city, state, country

when i type company name in the company field it will run validation to check wether the data is already in the database or not

if the data already exist then pop up the warning that the data is already exist, and if the data is not exist yet i can input the rest of the field

 

the code i'm trying to use to validate is

function validate()
	{
		$value = $this->input->get('value');
		$data = $this->Company_model->get_company_by_companyname ($value);
		
		$result = array();
		if($data)
		{
			$result['validate'] = 1;
			$result['url'] = site_url('company/edit/' . $data['id_company']);
		}
		else $result['validate'] = 0;		
		echo json_encode($result);
		
	}