I've spent the last two days trying to do a very simple thing and I cannot get it to work.
I have a view which lists a bunch of locations. I'm working on adding a search, so I added 3 exposed fields. These show up at the top as 30px textfields. Eventually, I want to try and turn these into checkboxes. But, to keep it simple, I'm currently JUST trying to change the size of the text fields. What function do I use? I've tried

(??)_form_alter - but I can't figure out what goes before this. it says "hook" so I've tried "views", the name of my template, the name of my view, etc. None of these work.

templatename_preprocess_views_exposed_form(&$vars, $hook) - I was able to get this one to change the name on the submit button, but I cannot figure out how to change the size of the field.

$vars['form']['submit']['#value'] = t('Search');
$vars['button'] = drupal_render($vars['form']['submit']);

This works. But this doesn't:

$vars['form']['fieldname']['#size'] = '5';
$vars['form_markup'] = drupal_render($vars['form']); // This is the line I have no idea what to write

phptemplate_views_filters

Can someone advise me as to the best function to use and the syntax that would get the field name changed? I really appreciate it!

Comments

visionmark’s picture

So I've tried creating a module called 'searchfields' and added into searchfields.module this code:

function searchfields_form_alter(&$form, $form_state, $form_id) {

if($form_id == 'views_exposed_form') {
$form['submit']['#value'] = 'Search';
}
}

And this seems to work. But again, adding
$form['fieldname']['#size'] = 5;

Is not working.

nevets’s picture

If after this line

$form['submit']['#value'] = 'Search';

your add (still inside the 'if' statement)

drupal_set_message('<pre>'  .   print_r($form,  TRUE) . '</pre>');

when visiting the view you will be able to see all the form fields making it easier to make the changes you want.

visionmark’s picture

That's helpful! Thanks!

visionmark’s picture

One of my fields is a select box by default. When I leave it at default, and no values are selected, it shows all values. However, when I turn it into "checkboxes" and no value is selected, it returns no results (nothing selected). Any ideas why this is?

colincalnan’s picture

So I've found that you have to unset the [#printed] array element for form element you want to change

function yourtheme_preprocess_views_exposed_form(&$vars) {
  $vars['form']['submit']['#value'] = t('Search');

  unset($vars['form']['submit']['#printed']); // unset the form element printed variable...

  $vars['button'] = drupal_render($vars['form']['submit']);
}

So in your case, you could do something like

$vars['form']['fieldname']['#size'] = '5';
unset($vars['form']['#printed']); // unset the form printed variable...
$vars['form_markup'] = drupal_render($vars['form']); // This is the line I have no idea what to write

This frustrated the hell out of me, until I remembered a solution for theming the search form http://drupal.org/node/224183#comment-1229386.
Hope this helps.