When I submit form created with Form API, the POST variable contains values like form_token, form_build and form_id.

The problem is, I need to send submitted form values to external website. Is it possible to remove such values from POST request?

In particular, I am implementing redirection callback to commerce payment method

This callback is defined within Drupal Commerce. The callback works OK, but how can I remove the mentioned form parameters? (The third party payment service does not accept them in received POST variable).

I am not sure whether I can just unset them in hook_form_alter. This callback is just part of the order process and I am not sure if I can just unset it.

1 Answer 1


You can make a call to external website using drupal_http_request in form submit handler.. Define extra submit handler using hook_form_alter and

$form['#submit'][] = 'YOUR_FORM_SUBMIT_HANDLER';

For Example

// Adds a submit handler/function for your form

function YOUR_FORM_SUBMIT_HANDLER($form, &$form_state) {

    $options = array();
    // Array keys are matching the key that the remote site accepts. URL encoding will be taken care later.
    $options['data'] = array(
        'firstName' => $form_state['values']['firstName'],
        'lastName' => $form_state['values']['lastName'],
        'email' => $form_state['values']['email'],
        'name' => $form_state['values']['name'],
        'phone' => $form_state['values']['phone'],
    $options['data'] = http_build_query($options['data']);
    $options['method'] => 'POST';
    $url = 'https://[url path to external site]'; 

    // Put your additional headers here. Cookie can be set as well. 
    $headers = array('Content-Type' => 'application/x-www-form-urlencoded');

    $options['headers'] => $headers;

    // Submits data to the remote server from the drupal server. User will remain in the Drupal form submission chain.
    $response = drupal_http_request($url, $options);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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