⚠ 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

Field Required Validation Based on Another Field's Input



Iszuddin Ismail

Iszuddin Ismail
  • profile picture
  • Member

Posted 16 October 2017 - 23:43 PM

Let say I have a field, user_type, which is an enum field. The options, paid or free.

 

And I have another field, paid_expiry. I want paid_expiry to be required if user_type is paid. But it is not required if user_type is free.

 

Is there a way to accomplish this?


Iszuddin Ismail

Iszuddin Ismail
  • profile picture
  • Member

Posted 17 October 2017 - 01:10 AM

Nevermind. I figured it out.

		$state = $gc->getState();
		if($state == 'insert_validation') {
			if ($this->input->post('paid_user') == 'paid') {
				$this->gc->set_rules('paid_expiry','Paid Expiry','required');
			}
		}