Modify/change views exposed filters form elements

Public

An example how you can modify a form element from a views exposed filter.

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_form_alter().
  3.  */
  4. function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
  5.  
  6. // Switch the title textfield to a predefined select box
  7. if ($form['#id'] == 'views-exposed-form-VIEW-NAME') {
  8. $options = array('' => t('- Any -'));
  9.  
  10. $results = db_select('node', 'n,')
  11. ->fields('n', array('title'))
  12. ->condition('n.type', 'NODETYPE', '=')
  13. ->condition('n.status', 1, '=')
  14. ->orderBy('n.title')
  15. ->execute();
  16.  
  17. foreach ($results as $result) {
  18. $options[$result->title] = $result->title;
  19. }
  20.  
  21. // Overwrite the textfield form settings
  22. $form['title']['#type'] = 'select';
  23. $form['title']['#size'] = '1';
  24. $form['title']['#options'] = $options;
  25. }
  26. }

Comments

Hitesh Bhargav's picture

is there any way to change views exposed form submit method GET to POST ??