Jump to content


Rule under condition

rules validation

  • Please log in to reply
2 replies to this topic

#1 Adriano Gonçalves

Adriano Gonçalves

    Member

  • Members
  • PipPip
  • 15 posts

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



#2 Amit Shah

Amit Shah

    grocery CRUD Master

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

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 :)



#3 Adriano Gonçalves

Adriano Gonçalves

    Member

  • Members
  • PipPip
  • 15 posts

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!







Also tagged with one or more of these keywords: rules, validation

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users