CodeIgniter Forums
form_validation two is_unique - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: form_validation two is_unique (/showthread.php?tid=69234)



form_validation two is_unique - oscarenzo - 10-23-2017

Hello

I've a little issue, in my view receive one param by post named GatewayId

This is my controller

Code:
$this->load->model("DeleteExpense_model");

   $GatewayId = $this->input->post('GatewayId');

   $this->form_validation->set_rules('GatewayId', 'GatewayId', 'is_unique[tab_expense.tab_gateway_id]');
   $RESULTA=$this->form_validation->run();

   $this->form_validation->set_rules('GatewayId', 'GatewayId', 'is_unique[tab_income.tab_gateway_id]');
   $RESULTE=$this->form_validation->run();

I want to check in two tables, then problem is that return false in both cases, if I run by separate work as well, it should retunr in the first case true and false in the other but seems like the second check overwrite the first, can somebody help me?

Thank you advance!.


RE: form_validation two is_unique - oscarenzo - 10-24-2017

If somebody can be util, I could fix it using the function 
Code:
$this->form_validation->set_data($data);
of this way:

Code:
$data = array(
       'GatewayIdOne' => $GatewayId,
       'GatewayIdTwo' => $GatewayId
   );

   $this->form_validation->set_data($data);
   $this->form_validation->set_rules('GatewayIdOne', 'GatewayIdOne', 'is_unique[tab_expense.tab_gateway_id]');
   $this->form_validation->set_rules('GatewayIdTwo', 'GatewayIdTwo', 'is_unique[tab_income.tab_gateway_id]');

Now when run the form check return correct, thank you,

PD: If some guru can suggest if is that correct way to do this or not I will be grateful, regards.


RE: form_validation two is_unique - PaulD - 10-24-2017

Does this not work?

PHP Code:
$this->form_validation->set_rules('GatewayId''GatewayId''is_unique[tab_expense.tab_gateway_id]|is_unique[tab_income.tab_gateway_id]'); 

i.e, just run the two rules one after another.

Alternatively the way you have done it in your second suggestion also seems fine.

Paul

PS I have not tested it but it looks like it might work.


RE: form_validation two is_unique - oscarenzo - 10-24-2017

(10-24-2017, 11:01 AM)PaulD Wrote: Does this not work?

PHP Code:
$this->form_validation->set_rules('GatewayId''GatewayId''is_unique[tab_expense.tab_gateway_id]|is_unique[tab_income.tab_gateway_id]'); 

i.e, just run the two rules one after another.

Alternatively the way you have done it in your second suggestion also seems fine.

Paul

PS I have not tested it but it looks like it might work.

Thanks!, it work, I saved 8 lines in my code, best regards.