1

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.

2
  • 1
    In order for the form to be submitted correctly the element needs to be a submit, button or image_button type. An element of type markup 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
    – Clive
    Mar 8 '13 at 11:09
  • Yes, to expand on what Clive said, a form array does two jobs: (1) telling the API what HTML to generate for a form, and (2) telling it how to process input from it. Your code is doing the first one without the other. Mar 8 '13 at 13:28
0

Try to use this:

Drupal 6:

 $form['actions']['submit']['#type'] = "Submit";

Drupal 7:

$form['actions']['submit'] = array(
  '#type'  => 'submit',
);
0

I just had the same problem. All the needed was adding this.

$form['actions']['submit'] = array(
  '#type'  => 'submit',
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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