How to remove the form_state, form_id and form_build_id when submitting a form? I have been creating a payment gateway integration module for Drupal 7.

When I post the form to the payment gateway API, it is posting extra variables like form_id, form_build_id, and form_token.

Can anybody tell me a way to eliminate these extra variables?
In Drupal 7, you can use the form_state_values_clean() function that removes:


form_id
form_token
form_build_id
op


Usage example:

&lt;?php
/**
 * Let's say this is your form.
 */
function your_form($form, &amp;$form_state) {
  // Form items go here.

  // Let's add the form actions element...
  $form['actions'] = array(
    '#type' =&gt; 'actions',
  );

  // ...and the form submission button with a function callback that removes
  // 'form_id', 'form_token', 'form_build_id' and 'op' values upon form submit.
  $form['actions']['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
    '#submit' =&gt; array('your_form_submit'),
  );
}

/**
 * And this is the submission handler/callback for your form where
 * 'form_id', 'form_token', 'form_build_id' and 'op' values will be removed.
 */
function your_form_submit($form, &amp;$form_state) {
  // Let's unset 'form_id', 'form_token', 'form_build_id' and 'op'.
  form_state_values_clean($form_state);

  // Now the $form_state['values'] doesn't contain 'form_id', 'form_token',
  // 'form_build_id' and 'op'.
  $form_values = $form_state['values'];

  // Do the rest…
}