We need a <button>
instead of an input in our search-form. So I changed the markup accordingly using theme_form_alter
:
function giga_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['search_block_form']['#title'] = t('Search'); // Change the text on the label element
$form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
$form['search_block_form']['#size'] = 40; // define size of the textfield
$form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield
$form['actions']['submit'] = array(
'#type' => 'markup',
'#prefix' => '<button type="submit" class="btn btn-primary">',
'#suffix' => '</button>',
'#markup' => '<i class="icon-search icon-white"></i>'
);
$form['actions']['submit']['#executes_submit_callback'] = true;
$form['actions']['#type'] = 'none';
$form['#attributes']['class'][] = 'search-quick';
// Alternative (HTML5) placeholder attribute instead of using the javascript
$form['search_block_form']['#attributes']['placeholder'] = t('Search');
}
}
However, I can submit the form, but the search won't be processed. The page reloads and I'm not redirect to the search results. However when I remove $form['actions']['submit'] = array([…]);
it all works fine.
I'm not quite sure what's going on here.
submit
,button
orimage_button
type. An element of typemarkup
can never invoke a form submission as it doesn't make semantic sense. You can actually infer that from the docs for#executes_submit_callback
themselves