Views Exposed filter as checkboxes and radio button

ashiwebi - August 14, 2009 - 12:21

How I can add views exposed filter as checkbox or radiobutton rather then select list

Use hook_form_alter() on the

j_ten_man - August 14, 2009 - 13:45

Use hook_form_alter() on the views_exposed_form. You can then change the type from select to radios or checkboxes.

Thanks

ashiwebi - August 17, 2009 - 05:40

Thank you

When one door closes,another opens, but if we spend too much time concentrating on the closed door we don't notice the open one.

Hi, looking for the same

czeky - August 21, 2009 - 06:08

Hi, looking for the same thing, did You managed how to? Thank You

help with php code

wintercat - August 21, 2009 - 07:10

I'm also trying to implement this, but I am new to php, and am struggling with the code. So far, I have created a basic custom module which is working. (The module currently uses hook_form_alter to remove a few fields from the node edit form, as described in a helpful tutorial at http://geeksandgod.com/tutorials/computers/cms/drupal/creating-simple-dr....)

I am now trying to add code to the mysite.module file to tell my Views multiselect taxonomy exposed filter to display as checkboxes.

I am getting the following error message:
Parse error: syntax error, unexpected ')', expecting ']' in...

My code is:

<?php
// $Id$

/*
* @file
* Drupal Module: mysite
* Adds custom code specific to this Drupal 6 site.
*/

function mysite_form_alter(&$form, &$form_state, $form_id) {
// print $form_id;
// uncomment the line above and form names will appear at the top of your page
  switch ($form_id) {
    case 'makers_directory_listing_node_form':
      // remove some unwanted node editing fields
      $form['revision_information']['#access'] = 0;
      $form['menu']['#access'] = 0;
      $form['author']['#access'] = 0;
      // override node options permissions defined by 'administer nodes'
      $form['options']['#access'] = 1;
      $form['options']['status']['#access'] = 1;
      $form['options']['promote']['#access'] = 0;
      $form['options']['sticky']['#access'] = 0;
// this next bit can be uncommented to show all the existing form elements, any of which can be altered.
// $form['form_array'] = array(
//   '#value' => '<pre>'. print_r($form, 1) .'</pre>',
//   '#weight' => '99',
// );
  }
if ($form_id == 'views_exposed_form') {
$form['taxonomy'][#type] = 'checkbox';
);
  }
}

Any help is much appreciated! Thanks.

Hi all, showing exposed

peter-boeren - August 21, 2009 - 10:31

Hi all,

showing exposed filters with a radio or a checkbox is something that is much needed by many people. I have started a module a month ago or so. It works and needs also tons of love and care before it is ready. But I've already received some positive feedback. You can give it a try (project page: Views filter pack)

views filter pack

wintercat - August 22, 2009 - 09:47

Thanks Peter. I'd seen your project page & the module sounds great.

I'm still hoping to get my snippet of code working in the meantime!

Change this: if ($form_id ==

benschulkin - August 23, 2009 - 22:43

Change this:

if ($form_id == 'views_exposed_form') {
$form['taxonomy'][#type] = 'checkbox';
);

To this:

if ($form_id == 'views_exposed_form') {
$form['taxonomy']['#type'] = 'checkbox';

... that should get rid of your PHP error ... don't know if you'll get checkboxes though

thanks!

wintercat - August 24, 2009 - 09:04

Thanks so much for the correction. You're right though - it got rid of the error, but just produced an extra checkbox rather than displaying my multiselect taxonomy as checkboxes... but at least I can move forward now. I have a few books on PHP so I'll keep experimenting :)

Hi, can't get it to work, I

czeky - September 2, 2009 - 22:22

Hi, can't get it to work, I have custom CCK field called "field_district", but I'm lost how to find the right name for this select box

<?php
if ($form_id == 'views_exposed_form') {
$form['field_district']['#type'] = 'checkbox';
}
?>

doesnt work

Hey czeky, have you already

peter-boeren - September 3, 2009 - 05:05

Hey czeky,

have you already printed the $form-variable? Try something like this on the first line after mymodule_hook_form_alter(&$form, $form_state, $form_id)) {

var_dump($form);

or

print "<pre>";
print_r ($form);
print "</pre>";

this way you know how your form looks like before altering it. I hope this helps in your quest.

kind regards,

thanx, I'm a little bit more

czeky - September 3, 2009 - 05:46

thanx, I'm a little bit more lost, there are more than 100 "field_district_xxx_yyy" items, could you please point me which one use?

looking like

[filter-field_district_value_many_to_one] => Array
(
[operator] => field_district_value_many_to_one_op
[value] => field_district_value_many_to_one
[label] => District
)

really thank you guys here

100 seems like a lot.

j_ten_man - September 4, 2009 - 12:04

100 seems like a lot. Normally you would do something like

<?php
  $form
['field_district_value_many_to_one']['#type'] = 'checkboxes';
?>

Not quite sure what or why you are seeing what you are...

Can you save your results to

j_ten_man - September 4, 2009 - 22:34

Can you save your results to a text file and then save it somewhere from your dump? I would like to take a look but we don't need all that information in this thread, just a link to download it would be great.

I am attempting to do

bjraines - October 23, 2009 - 14:11

nvm

Free Chemistry Tutoring - www.mychemistrytutor.com

Better Exposed Filters

mikeker - November 24, 2009 - 23:00

I just contributed a module called Better Exposed Filters which gives you a per-filter option of using the default select box or radio buttons/checkboxes. I've tested it with Taxonomy fields, CCK fields and core node fields and would appreciate any help with additional compatibility testing or suggestions.

I was having problems using Views Filter Pack with multiple exposed filters. BEF takes a different approach and comes at the problem from the theming side of things.

Hope that helps.

- Mike

- Mike

 
 

Drupal is a registered trademark of Dries Buytaert.