Skip to content
Advertisement

how to send multiple checkbox data with `|` delimeter using codeigniter form

I want to send multiple checkbox data using | delimiter in CodeIgniter form

In my form, I use the checkbox to select multiple data:

  <form method="get" action="<?PHP echo base_url();?>search">
        <input type="checkbox" name="cats" value="1234">Sylhet 
        <input type="checkbox" name="cats" value="1235">Dhaka
        <button>Search Now</button>
  </form>

now it sends like: search?cats=1234&cats=1235

but I want it to send like search?cats=1234|1235

Advertisement

Answer

You should send it using name="cats[]" and get your checkbox data in Controller:

$cats = $this->input->get('cats',true);

the variable $cats will return an array. if you need data1|data2 string, you can construct it in your controller by looping each array.

However if for somewhat reason you need to need to pass the checkbox data in search?cats=data1|data2 format, you can use a hidden field and change the hidden field value everytime you checkbox changed.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement