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:

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

  // Let's add the form actions element...
  $form['actions'] = array(
    '#type' => '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' => 'submit',
    '#value' => t('Submit'),
    '#submit' => 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, &$form_state) {
  // Let's unset 'form_id', 'form_token', 'form_build_id' and 'op'.

  // 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…

I would create a form handler and submit the results via AJAX.

Meaning, take your form, submit it and take the response and parse it for the information you are interested in packaging it up and sending it off as an AJAX request to your payment gateway API.

As Ayesh said, these are important parts of the form and are not intended to be left out.

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.