Custom exposed filter with single on/off checkbox doesn't respect the default value and the $_GET parameter I've created a custom filter with a checkbox exposed field in my module.

class my_module_helper_handler_filter_timetracking_children extends views_handler_filter {

  /*...*/

  function value_form(&amp;$form, &amp;$form_state) {
    $form['value'] = array(
      '#type' =&gt; 'checkbox',
      '#title' =&gt; t('Show subtasks'),
      '#default_value' =&gt; isset($this-&gt;value) ? $this-&gt;value : NULL,
    );
    return $form;
  }

  /*...*/

}


When by default in Views UI settings checkbox is disabled, everything works fine; when it's enabled, it doesn't work. It doesn't respect the default value and the $_GET parameter.

I can't understand this strange behavior of single on/off checkboxes in exposed filters in a view.

I also tried using '#attributes' =&gt; array('checked'=&gt;'checked'), but the filter didn't work correctly.

Might somebody can show his code how to create custom exposed filter with single checkbox? Or give usefull link
Views doesn't handle the default checkbox state because when you load your view page for the first time (or if the user clicks the Reset button), the URL doesn't have any parameter in it, so that the $_GET parameter is useless. Here is a complete form definition that will handle the checkbox, whether the URL has parameters or not:

class my_module_helper_handler_filter_timetracking_children extends views_handler_filter {

  /*...*/

  function value_form(&amp;$form, &amp;$form_state) {

    $params = my_module_get_params();

    // First time the view is loaded (or user click the Reset button), URL doesn't have parameters
    if(!$params) {
      $value = 1; // checkbox checked by default
    }
    // If URL has parameters
    else {
      // If our filter is present in the URL as parameter and its value is '1'
      if (isset($params['timetracking_children']) &amp;&amp; $params['timetracking_children'] == 1) {
        $value = 1;
      }
      else {
        $value = 0;
      }
    }

    $form['value'] = array(
      '#type' =&gt; 'checkbox',
      '#title' =&gt; t('Show subtasks'),
      '#default_value' =&gt; isset($this-&gt;value) ? $this-&gt;value : NULL,
      '#value' =&gt; $value,
    );
    return $form;
  }

  /*...*/

}

function my_module_get_params() {
  global $base_url;
  $query = array();

  $url = $base_url.request_uri();
  $url = parse_url($url);

  if(isset($url['query'])) {
    parse_str($url['query'],$query);
  }

  return $query;
}