Get KoolPHP UI with 30% OFF!

Validate field on user insert

Igor
Hi,
i have table with:
id, company_id, company,....
i want to validate field 'company_id' when user try to insert new company , if company_id already exist message is thrown.
I made a little progress for now, function is validating on user insert, but function is validating also on user update so user canĀ“t update without changing company_id.
	function my_validate_function($company_id){
		
		if (mysql_num_rows(mysql_query("SELECT company_idFROM client WHERE company_id= '".$company_id."'")))
		{
			return "Company already exist.";
		}
		else
		{
			return null;
		}
	}
	$column = new GridBoundColumn();//GridBoundColumn is inherited from GridColumn
	$validator = new CustomValidator();
	$validator->ValidateFunction = my_validate_function;
	$column->AddValidator($validator);
	$column->DataField = "company_id";
	$column->HeaderText = "company_id";
	$grid->MasterTable->AddColumn($column);

chears
igor
Posted Jun 20, 2016 Kool