Hvel
Hvel

Reputation: 65

How to retain the value is select2 after form submit in Codeigniter?

I have a select2 on my view, but when the user clicks submit on the form and the validation fails the previously selected values are cleared.

I tried using set_select() but it does not work.

Hoping that someone has encountered the same and had a solution.

Upvotes: 0

Views: 644

Answers (1)

Hvel
Hvel

Reputation: 65

I got it, and for anyone who might benefit this is how I managed to do it:

On the controller:

 $data['selected_values'] = implode(", ", $this->input->post('nameOfselect2')); 

and then pass it back to the view.

Upvotes: 2

Related Questions