PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

Drupal Views Exposed Computed Field Dropdown Select

January24

In views I wanted to expose a computed field but instead of textbox I wanted it to be a select drop down box with values coming from the database.

To achieve this I created a module and used the hook form_alter:

function mymodule_form_alter(&$form, $form_state, $form_id) {
switch(
$form_id) {

 case 'views_exposed_form':

 if ($form['#id'] == 'views-exposed-form-search-jobseeker-page-1') {     
 $form['field_country_value']['#type'] = "select";
 $form['field_country_value']['#size'] = null;
 $form['field_country_value']['#multiple'] = true;
 $captain[''] = t('Any');
 $query = db_query("SELECT DISTINCT(field_country_value)FROM content_type_profile order by field_country_value asc");

 // Run through the results
 while($result = db_fetch_array($query)) {
 $construct = $result[field_country_value];
 $captain[$construct] = t($construct);
 }
 $form['field_country_value']['#options'] = $captain;
 }
 break;
}
}

Source: http://drupal.org/node/908544 
posted under Drupal

Email will not be published

Website example

Your Comment:

 

13,816 spam comments
blocked by
Akismet