⚠ 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

Small help on validation



Peter
  • profile picture
  • Member

Posted 17 December 2014 - 13:50 PM

Hi all, please try to imagine my situation I created 1 small function in which while editing first there will be dropdown which contains,

1.Approve
2.keep pending
3.Reject
$crud->field_type('status','dropdown', array('1' => 'Approve', '2' => 'keep pending','3'=>'Reject'));

and 1 more field that is reason field of type TEXT

 

if suppose I select either keep pending or Reject then reason field is mandatory, otherwise I don't have to enter anything in reason field, can someone tell me how this can be validated ?

 

 

Please guys help me

 

 

 


Amit Shah
  • profile picture
  • Member

Posted 18 December 2014 - 05:11 AM

u can use it in this way

 

$default_offer_if = $this->input->post('default_coupon') == '' ? '|required';

$crud->set_rules('expiry_condition', 'Expiry Condition',  'trim' . $default_offer_if);

 

this is an working example from 1 of my codes.. u can use it / alter it in your own way 2 satisfy..

 

This will generate the rule to check expiry condition to be required only if the default coupon is not set to any value.

 

Happy GCing :)


Peter
  • profile picture
  • Member

Posted 18 December 2014 - 06:44 AM

Awesome working great Master, thank you so much, you always been helpful.

   $required = ( $this->input->post('status') != 1 ? '|required' : "" ) ;
    $crud->set_rules('reason', 'reason',  'trim' . $required );