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
So I've tried creating a
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.
If after this
If after this line
your add (still inside the 'if' statement)
when visiting the view you will be able to see all the form fields making it easier to make the changes you want.
That's helpful! Thanks!
That's helpful! Thanks!
One of my fields is a select
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?
You have to unset the printed element
So I've found that you have to unset the [#printed] array element for form element you want to change
So in your case, you could do something like
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.