⚠ 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

Array Form Validati



karan
  • profile picture
  • Member

Posted 01 July 2013 - 06:38 AM

I am trying to validate an array field which is multiselect dropdown.But set_rules is completely ignoring the field.

 

$crud->set_rules('course_id[]','Course','trim|required');

 

$crud->field_type('course_id','multiselect',
                                array( "1"  => "VB", "2" => "Java", "3" => "C"));

 

 


Amit Shah
  • profile picture
  • Member

Posted 01 July 2013 - 07:15 AM

dont think you need to use .. 

$crud->set_rules('course_id[]','Course','trim|required');

 

rather - u can simply use $crud->set_rules('course_id','Course','trim|required');


karan
  • profile picture
  • Member

Posted 01 July 2013 - 08:35 AM

dont think you need to use .. 

$crud->set_rules('course_id[]','Course','trim|required');

 

rather - u can simply use $crud->set_rules('course_id','Course','trim|required')

 

But after putting the above statement, it will always show error of course_id even after selecting it.


davidoster
  • profile picture
  • Member

Posted 02 July 2013 - 08:55 AM

Please post your controller's code.


Json Sean
  • profile picture
  • Member

Posted 14 September 2017 - 08:52 AM

 

I am trying to validate an array field which is multiselect dropdown.But set_rules is completely ignoring the field.

 

$crud->set_rules('course_id[]','Course','trim|required');

 

$crud->field_type('course_id','multiselect',
                                array( "1"  => "VB", "2" => "Java", "3" => "C"));

 

 

 

You may solve  it by https://www.groceryc...157/#entry15517

 

Modify file of 'system/libraries/Form_validation.php':

 

in the function "public function run($group '')",before _execute action add codes like this:

 

...

 

if(in_array('required',$row['rules']) and is_array($row['postdata'])){
      $row['postdata'] = json_encode($row['postdata'],JSON_UNESCAPED_UNICODE);
}

 

...
$this->_execute($row$row['rules'], $row['postdata']);