We want to silently submit a Drupal6 form to a marketing partner, and redirect the user to page on our site. Is this the correct syntax?

function my_form_submit($form, &$form_state) {
  $form_state['action'] = url('http://example.com/?method=cSurveyWebservice.submit&mode=test');
  $form_state['redirect'] = array('campaign/thank-you');

Certainly it processes and redirects, although I'm not sure how to independently validate if the form is actually posted to the specified URL.


1 Answer 1


You can try something like this

$request_url = 'http://your-url.com';
$request_headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$request_method = 'POST';
$request_retry = 2;
// form values you want to post
$form_values= array('apple' => 'red', 'banana' => 'yellow', 'pear' => 'green');
$data = http_build_query($fruits, '', '&');

// Send the request.
$response = drupal_http_request($request_url, $request_headers, $request_method, $data, $request_retry);

if ($response->code == 200) {
  $form_state['redirect'] = array('campaign/thank-you');
else {
drupal_set_message(t('There was a problem with your submission. Please try again later.'), 'error');

I haven't tried it but let me know if it works.

  • very nice, thanks. I implemented in a submit handler, and added the following to include the form elements in the request: '$skip_keys = array('submit', 'form_build_id', 'form_id'); foreach ($form_state['values'] as $key => $value) { if (!in_array($key, $skip_keys)) { $form_values[$key] = $value; }'
    – August1914
    Oct 23, 2012 at 23:46
  • @August1914 glad to hear it worked.
    – junedkazi
    Oct 24, 2012 at 1:19

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.