I'm using drupal 6 with the webform module installed.

I need to be able to remotely POST, from PHP results to a webform. Pseudocode:

//File: remote_script_not_hosted_on_the_same_server_as_drupal.php

$results = array(
'name' => 'testname',
'age' => '6',

$node = 5;

$url_to_drupal = 'http://remote_server.com/drupal-6.2';

insert_into_webform($results, $node, $url_to_drupal);

Of course, this example isn't perfect, but you (hopefully) get the idea.

How would you go about doing this?

I've opened an issue on the drupal queue: http://drupal.org/node/1082016

I'm concerned about these two fields invalidating my remote submission:

Content-Disposition: form-data; name="form_build_id"

Content-Disposition: form-data; name="form_token"

  • I've not tried it, but chapter 19 of Pro Drupal Development (I have the 2nd edition) refers to using xml-rpc to do this. It uses the page xmlrpc.php that's part of the standard install to do its work. – Tangurena Mar 5 '11 at 17:33

Have you tried using PHP to manually send the POST data? Here is a snippet from http://www.webmasterworld.com/php/3164561.htm

$server= 'www.someserver.com';
$url = '/path/to/webform/posturl';
$content = 'name1=value1&name2=value2';
$content_length = strlen($content);
$headers= "POST $url HTTP/1.0\r\nContent-type: text/html\r\nHost: $server\r\nContent-length: $content_length\r\n\r\n";
$fp = fsockopen($server, $port, $errno, $errstr);
if (!$fp) {
    return false;
fputs($fp, $headers);
fputs($fp, $content);
$ret = "";
while (!feof($fp)) {
    $ret .= fgets($fp, 1024);
print $ret;

Of course this would fail if you are using any form of captcha on the form, and will also currently fail if you are required to be authenticated to post a reponse

  • Yes, I thought about doing that, but upgrades (either of drupal, or of the webform module) might break this functionality. I was looking for a consitent API that I could use. If I don't get any better answers, I'll mark yours as the correct one. – xaav Mar 5 '11 at 16:11

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.