I intended to make a module that utilized drupal_http_request with a webform so that the form gets validated before it gets sent to an external url.

I actually was recommended this method over $form['#action'] from a previous inquiry earlier. I did as recommended, thought it worked, but found out that I was mistaken.

I did some troubleshooting and concluded my module is the culprit since:

  1. The module utilizing $form['#action'] had no problems posting to our external url/web app and another external site/service for testing HTTP POST submissions (http://requestb.in)

  2. The module utilizing drupal_http_post could neither post to our external url/web app nor requestb.in

My setup uses the following:

  • Drupal 6.x
  • Webform 6.x-3.17

My custom module contains the following code.

function webform_to_data_repo_form_submit(&$form, &$form_state, $form_id) {
    if ($form_id == 'webform_client_form_765') {
        $url = 'external.url.goes.here';
    $headers = array(
                 'Content-Type' => 'application/x-www-form-urlencoded',

$response = drupal_http_request($url, $headers, 'POST', http_build_query($form_state['values'], '', '&'));

Is there something wrong with my module? Just wanted to make it post to some external URL.

  • 1
    I don't completely understand how your result differs from your expectation. Is $response not an object as described in the API docs?
    – beth
    Jun 4, 2013 at 18:36
  • 1
    Check the out of $response at the end & see what it gives you..
    – RajeevK
    Jun 4, 2013 at 19:09
  • My apologies for not being completely clear. What I intended to do really was to make webform 765 to validate locally and post externally. As for the $response, it doesn't give me any for some reason. When I submit through the form, all I get really is a "Thank you, your submission has been received", but this is what one would get when you submit through a webform, right?
    – johnmiste
    Jun 4, 2013 at 20:17
  • Interestingly, my other module that uses $form['#action'] to submit externally instead of drupal_http_request returns an "ok" message. I would use $form['#action']. Problem is, I want the form to be validated before it submits externally, which is why I'm forced to use drupal_http_request.
    – johnmiste
    Jun 4, 2013 at 20:17
  • Install and enable the Devel module and then add a line at the end that says dpm($response); and tell us what shows up in the yellow box.
    – beth
    Jun 4, 2013 at 20:20

1 Answer 1


Thank you everyone for the pointers.

I realized that my custom module that uses the webform module to submit to an external url (via drupal_http_request) had to be written as two separate functions: one using hook_form_alter and one using a custom submit handler. The code is as follows.


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

//I only want form 765 to submit externally //
if ($form_id == 'webform_client_form_765') {
$form['#submit'][] = 'my_additional_submit_handler';

function my_additional_submit_handler(&$form, &$form_state) {

$url = 'your.external.url.here'
$headers = array('Content-Type' => 'application/x-www-form-urlencoded',);
$response = drupal_http_request($url, $headers, 'POST', http_build_query($form_state['values'], '', '&'));



As a side note, I never got to test the result of using dpm($response) using the Devel module as beth suggested.

I'm using a webform (via the webform module) to test. What I wanted to happen are two things.

  1. The webform validates the submission which in turn would keep a log of the submission through Drupal (webform module by default and by design).
  2. Simultaneously submit inputs from #1 to external url.

For the longest time, only #1 is happening and I can't seem to make Devel look into $response because that variable only exists when there's an attempt on submission. How does one make Devel module load when a successful submission has been made through a Webform? I guess this is another question for another time.

  • Do you think this might work on D7 ? Sep 22, 2015 at 20:25

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.