0

I am trying to alter my search form. I am following tutorial to learn drupal theming. I want to replace the search button with an image :

function mytheme_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['actions']['submit']['#type']= 'image_button';
$form['actions']['submit']['#src']= drupal_get_path('theme','MYTHEME').'/images/search.png';
$form['actions']['submit']['#attributes']['class'] [] = 'btn';
}
}

What i get in my page is the following result :

<input class="btn form-submit" type="image" id="edit-submit" name="submit" value="Search" src="http://mysite.com/sites/mysite.com/themes/MYTHEME/images/search.png">

However i want :

class="btn" 

And not

class="btn form-submit"

Did i miss something ?

Thanks !

1 Answer 1

3

A much much easier way to do this is leave it at the default style and use CSS to replace it with an image. That is how it is done 9 times out of 10.

Now onto the question at hand, Drupal automatically adds certain classes based on the form type. The only way to remove the default classes is to override the THEME_button function and do it there, for more information see https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_button/6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.