Вместо определения set_value()
с name[]
, попробуйте предоставить его без них. Я создал демо, и оно работает для меня. Посмотрите, работает ли это и для вас.
Вид
<?php
$attributes = array('method' => 'POST');
echo form_open('home/form', $attributes);
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
$attribute_tag = array(
'class' => 'some-class',
);
// this is the one you should be paying attention to ↓↓
echo form_multiselect('person_tags[]', $options, set_value('person_tags'), $attribute_tag);
$data = array(
'type' => 'text',
'name' => 'email',
'id' => 'email',
);
echo form_input($data, set_value('email'));
echo form_submit('mysubmit', 'Submit Post!');
echo form_close();
?>
Контроллер
function form(){
$this->load->library('form_validation');
$this->form_validation->set_rules('person_tags[]', 'Tags', 'required');
$this->form_validation->set_rules('email', 'text', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('vwHome');
}else{
echo 'No validation error'; die; // save in database(Your logic)
}
}
TL; DR
Измените свой текущий код на -
echo form_multiselect('person_tags[]', $options, set_value('person_tags'), $attribute_tag);