1

I need to add a page with a form in my Drupal website. This form should be submitted to another server (there is a php script ready to receive it on such server).

So, I don't need any database update, just a page forwarding the data inserted by users to another domain.

Do you know what's the easiest way to do it ?

thanks

ps. Also, I need to create a drop down menu with a list of countries (and regions for each country) as submenu

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
  • What form did you used? webform, cck, custom module? – Nikit Feb 16 '11 at 13:00
  • if it's important to hide the POST request see [drupal_http_request()](http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_http_request/6) and my updated answer – jpstrikesback Feb 16 '11 at 15:29

4 Answers4

3

I am surprised noone mentioned hook_form_alter and setting #action to an external URL. This will make the form post directly to the other server if you have control of it you can easily redirect back. Lot easier than POSTing from your server. Another way would be to iframe the other script and use the target attribute (set $form['#attributes']['target'] = 'the_iframe' in hook_form_alter). Then you can use JS to 'move' the page after the submit. Upload POSTs to an iframe, you can look into that JS as well. How do you post to an iframe? discusses iframes and forms.

Community
  • 1
  • 1
chx
  • 11,270
  • 7
  • 55
  • 129
  • I guess I was just trying to keep it PG :) which is perhaps silly once you start to put code in the DB... – jpstrikesback Feb 16 '11 at 14:23
  • If I use hook_form_alter can I send the data without forwarding the user ? What's important is hiding the url I'm sending the data. – aneuryzm Feb 16 '11 at 14:29
  • if hiding is important then server side is the only possibility for sure. – chx Feb 16 '11 at 16:15
  • So, if I use hook_form_alter is not hiding the url ? I thought the function is server side and I'm actually hiding it! – aneuryzm Feb 17 '11 at 08:32
  • By the way, can I use Devel dprint_r function for the registration form ? I'm actually having issues, because I need to be authenticated to use devel and I don't see the registration form if I'm not logged in.. – aneuryzm Feb 17 '11 at 08:36
1

In your form, you can set #action to whatever URL you want. It will post to that url. If you need a GET, instead of a POST, you should also set the #method.

function my_form_builder() {
  $form['search'] = array(
    //..builds some form elements
  );

  $form[#action] = 'http://example.com';

  return $form;

}

berkes
  • 26,996
  • 27
  • 115
  • 206
0

You could create a regular drupal form with the ususal validation stuff and instead of putting the date into the DB send it over to the other site (via post or get or whatever).

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
0

To POST to an external URL in your own custom form implementation or using hook_form_alter() to add another submit handler to an existing form, while not showing the request you will want to use drupal_http_request() to send a serverside http request. See this:

http://www.drupaler.co.uk/blog/validating-submitting-forms-other-websites-drupal/428

To accomplish this with the webform module you'll need what you learned above and something like the following:

  1. In D6 /Webform < 3

    http://drupal.org/node/543674#comment-2499674

  2. In Drupal 7/Webform 3

    http://www.midwesternmac.com/blogs/jeff-geerling/integrate-webform-3x-paypal

jpstrikesback
  • 2,300
  • 14
  • 18