0

I need to implement multiple choice and it is something like this:

<ul>
   <li><input type="checkbox" name="mediaChannelFilter[]" onchange="this.form.submit()" class="test" value="1" {{ (Request::get('mediaChannelFilter[]')==1) ? "checked":"" }}>&nbsp;TV</li>
   <li><input type="checkbox" name="mediaChannelFilter[]" onchange="this.form.submit()" class="test" value="2" {{ (Request::get('mediaChannelFilter[]')==2) ? "checked":"" }}>&nbsp;Print</li>
   <li><input type="checkbox" name="mediaChannelFilter[]" onchange="this.form.submit()" class="test" value="3" {{ (Request::get('mediaChannelFilter[]')==3) ? "checked":"" }}>&nbsp;Radio</li>
   <li><input type="checkbox" name="mediaChannelFilter[]" onchange="this.form.submit()" class="test" value="4" {{ (Request::get('mediaChannelFilter[]')==4) ? "checked":"" }}>&nbsp;OoH</li>
 </ul>

In controller I use this input value and filter through results. Btw I'm using this package for Sphinx search - https://github.com/sngrl/sphinxsearch

$mediaChannelFilter = Input::get('mediaChannelFilter');
if (!empty($mediaChannelFilter)) {
            $results = $cl->filter('mediatype', [$mediaChannelFilter]);
        }

But it only filters with one parameter (the last one clicked), not the whole array. Also it doesn't mark my input field as checked. What should I change here?

{{ (Request::get('mediaChannelFilter[]')==1) ? "checked":"" }}
harunB10
  • 4,823
  • 15
  • 63
  • 107
  • if you do `dd($mediaChannelFilter);` you get array of all selected checkboxes? – Autista_z Apr 19 '17 at 16:29
  • Yep! But, because of onclick submit, I need to go back one page and choose another option, and in this case the array is increasing. – harunB10 Apr 19 '17 at 16:32
  • In vanilla PHP, `$_GET['mediaChannelFilter']` would be an array. And according to comment, sounds like case via 'Input::get' too. So in Filter(), would pass it directly, not wrapped in [..] - is its already an array, dont need to make it an array (of one) – barryhunter Apr 20 '17 at 11:34
  • 1
    Similarly, in the checked could use in_array() - eg `in_array(1, Request::get('mediaChannelFilter'))?"checked":""` – barryhunter Apr 20 '17 at 11:36

0 Answers0