Removing Drupal GET Form apparently unnecessary parameters I have a FORM built with Drupal 7 Form API, with URL (action) pointing to:

www.example.com/search-products


and the default method POST. My SEO mate has asked me to change the method to GET, so for SEO indexing purposes the URL will be explicit, for example:

www.example.com/search-products?brand=BRAND%201&amp;model=Model%20Fantastic


I have changed the behaviour of the form by adding the following line at the end of the hook_form function:

$form["#method"] = "get";


Now the problem is that the generated URL has some "extra" info that I wouldn't want to be displayed. And it is apparently unnecessary, because if the View (landing page of the FORM) is paged, if I only pass the above parameters + the page, it works perfectly, also if I remove this extra info by hand.

The "ugly" URL is:

www.example.com/search-products?brand=BRAND%201&amp;model=Model%20Fantastic&amp;op=Submit&amp;form_build_id=form-Ab-i8LlsUjtftyuTlL8b7OvZj_tM1MfyuKCnAg5-VncY&amp;form_id=hook_form

(extra info: ... &amp;op=Submit&amp;form_build_id=form-Ab-i8LlsUjtftyuTlL8b7OvZj_tM1MfyuKCnAg5-VncY&amp;form_id=hook_form )


How can I make Drupal ignore that extra info?
Here's a workaround you can use:

    $form['#after_build'][] = 'mymodule_form_modify';


Then:

    function mymodule_form_modify($form){
      unset($form['form_token']);
      unset($form['form_build_id']);
      unset($form['form_id']);
      return $form;
    }


And finally to get rid of the &amp;op parameter:

    $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Submit'),
      '#name' =&gt; '',
    );


Source.