⚠ 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

Rule under condition



Adriano Gonçalves
  • profile picture
  • Member

Posted 07 October 2015 - 10:13 AM

Hi guys,

I would like to know if is there any way to create, in GC, a validation rule under a condition. For example, if (only if) Field_A is filled, Field_C is required.

 

Thanks in advance!

 

Adriano


Amit Shah
  • profile picture
  • Member

Posted 12 October 2015 - 08:31 AM

i will share an example which u can follow and change as u need

 

            $required_if = $this->input->post('new_password') ? '|required' : '';
            $validation_check = $this->input->post('new_password') ? '|required|matches[confirm_passwd]' : '';
            $crud->set_rules('confirm_passwd', 'New Password', 'trim' . $required_if);
            $crud->set_rules('new_password', 'New Password Again', 'trim' . $validation_check);

Happy Gcing :)


Adriano Gonçalves
  • profile picture
  • Member

Posted 26 October 2015 - 08:14 AM

 

i will share an example which u can follow and change as u need

 

            $required_if = $this->input->post('new_password') ? '|required' : '';
            $validation_check = $this->input->post('new_password') ? '|required|matches[confirm_passwd]' : '';
            $crud->set_rules('confirm_passwd', 'New Password', 'trim' . $required_if);
            $crud->set_rules('new_password', 'New Password Again', 'trim' . $validation_check);

Happy Gcing :)

 

 

Very interesting approach! Thank you!