Remove the default value Is it possible to remove the default value an exposed filter (implemented by the Better exposed filter module) in a view? I would like to have users choose a value.

I tried using this in the template file, but nothing changed.

function custom_theme_form_views_exposed_form_alter(&amp;$form, &amp;$form_state) {
  // dpm($form);
  if ($form['#id'] == 'views-exposed-form-betterexposed-page-1') {
    foreach(element_children($form) as $key =&gt; $value) {
      if (isset($form[$key]['#type']) &amp;&amp; $form[$key]['#type'] == 'select') {
        array_shift($form[$key]['#options']);
      }
    }
  }
}


The HTML markup is now the following.

&lt;form action="/be1" method="get" id="views-exposed-form-betterexposed-page-1" accept-charset="UTF-8" class="jquery-once-1-processed"&gt;&lt;div&gt;&lt;div class="views-exposed-form"&gt;
  &lt;div class="views-exposed-widgets clearfix"&gt;
          &lt;div id="edit-status-wrapper" class="views-exposed-widget views-widget-filter-status"&gt;
                  &lt;label for="edit-status"&gt;
            Published          &lt;/label&gt;
                        &lt;div class="views-widget"&gt;
          &lt;div class="form-item form-type-radios form-item-status"&gt;
 &lt;div id="edit-status" class="form-radios bef-select-as-radios"&gt;&lt;div class="form-item form-type-radio form-item-status"&gt;
 &lt;input class="bef-select-as-radios form-radio" type="radio" id="edit-status-1" name="status" value="1" checked="checked"&gt;  &lt;label class="option" for="edit-status-1"&gt;Yes &lt;/label&gt;

&lt;/div&gt;
&lt;div class="form-item form-type-radio form-item-status"&gt;
 &lt;input class="bef-select-as-radios form-radio" type="radio" id="edit-status-0" name="status" value="0"&gt;  &lt;label class="option" for="edit-status-0"&gt;No &lt;/label&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class="description"&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
        &lt;/div&gt;
              &lt;/div&gt;

                    &lt;div class="views-exposed-widget views-submit-button"&gt;
      &lt;input type="submit" id="edit-submit-betterexposed" name="" value="Apply" class="form-submit"&gt;    &lt;/div&gt;
      &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;/form&gt;


I also tried the following code.

function custom_theme_form_views_exposed_form_alter(&amp;$form, &amp;$form_state) {
foreach(element_children($form) as $key =&gt; $value) {
    if (isset($form[$value]['#type']) &amp;&amp; $form[$value]['#type'] == 'select') {

      $options = $form[$value]['#options'];
      $newOptions = array();

      for ($i = 0, $optionsCount = count($options); $i &lt; $optionsCount; $i++) {
        $optionsKey = array_keys($options[$i]-&gt;option);
        $optionsValue = array_values($options[$i]-&gt;option);

        $newOptions[$optionsKey[0]] = $optionsValue[0];
      }

      unset($form[$value]['#multiple']);

      $form[$value]['#type'] = 'radios';
      $form[$value]['#options'] = $newOptions;
      $form[$value]['#theme'] = 'select_as_radios';
    }
  }
}


I now get the following notice and warning messages.


  Notice: Trying to get property of non-object in
  custom_theme_form_views_exposed_form_alter()
  Warning: array_keys() expects parameter 1 to be array, null given in
  custom_theme_form_views_exposed_form_alter()
May be something like this (with hook_form_FORM_ID_alter function): 

function MYMODULE_form_views_exposed_form_alter(&amp;$form, &amp;$form_state) {
  // dpm($form);
  if ($form['#id'] == 'MY_EX_FORM_ID') {
    foreach(element_children($form) as $key =&gt; $value) {
      if (isset($form[$key]['#type']) &amp;&amp; $form[$key]['#type'] == 'select') {
        array_shift($form[$key]['#options']);
      }
    }
  }
}


EDIT:

Ok, it seems that better exposed filter doesn't allow to remove default value from radio if settings are default (with default settings, filter -> is one of, BEF Settings -> checkboxes/radio buttons). I realized that in my project radios have been made from checkboxes type (with alter function), that's why in my example it's working fine..

here is a working example:




in hook_form_form_id_alter function:

foreach(element_children($form) as $key =&gt; $value) {
    if (isset($form[$value]['#type']) &amp;&amp; $form[$value]['#type'] == 'select') {

      $options = $form[$value]['#options'];
      $newOptions = array();

      for ($i = 0, $optionsCount = count($options); $i &lt; $optionsCount; $i++) {
        $optionsKey = array_keys($options[$i]-&gt;option);
        $optionsValue = array_values($options[$i]-&gt;option);

        $newOptions[$optionsKey[0]] = $optionsValue[0];
      }

      unset($form[$value]['#multiple']);

      $form[$value]['#type'] = 'radios';
      $form[$value]['#options'] = $newOptions;
      $form[$value]['#theme'] = 'select_as_radios';
    }
  }