If I create a custom form with get method:

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

When I click the submit button, many variables are populated with GET Can I remove them cleanly according to the drupal logic?


You need to alter the form after it has been built, for example

$build = [];
$build['filter'] = $this->formBuilder->getForm(LibrarySearch::class);
$build['filter']['form_id']['#access'] = FALSE;
$build['filter']['form_build_id']['#access'] = FALSE;
$build['filter']['form_token']['#access'] = FALSE;

Once the form has been turned into a render array, you can set the access to FALSE for those items. This is also documented in the core Search module.

| improve this answer | |

Another way to solve this problem.

Implement a hook form alter in your corresponding module in the

[name_of_your_module].module file, just add

 * Implements hook_form_FORM_ID_alter().
 * Need to don't see the parameters 'form_build_id' and 'form_id' in the url.
function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
  unset($form['form_build_id'], $form['form_id']);
| improve this answer | |

Needs to alter the form to unset form_id and form_build_id. In bellow code formid is the id of the form where you want to remove form_id and form_build_id.

function mymodule_form_formid_alter(&$form, &$form_state, $form_id) {

unset($form['form_build_id'], $form['form_id']);


| improve this answer | |

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.