How do i send HTTP POST/GET data to drupal?

for example: I've got a html form:

<form action="mydrupalcite.com" method="get">
    <input type="text" name="title" />

how do i get the title 's data into drupal's answers module?(or any module?)

I'm looking for the drupal way of doing this(i'm relatively new to Drupal and how it really works)

Does it have anything to do with Services module?

  • i'm not really looking for creating forms, but sending data to a form in drupal(a question module form)
    – tom91136
    Sep 7, 2012 at 15:01
  • Ok I thought otherwise check out Clives response.
    – GoodSp33d
    Sep 7, 2012 at 15:03

2 Answers 2


Drupal's form API has CSRF protection built in, so submitting a form from an external domain won't work. You could either look at disabling the CSRF (very bad idea), or as you suggest, use the Services module.

There's no one-to-one mapping between the services module and forms on the site, rather modules implement resources for certain tasks to be consumed from an external client. You get node, user, taxonomy term, and probably others by default. So you can (for example) add a new node/user/term, but you do so by sending xml/json/etc requests to the server after having authenticated, not by submitting a form as such.

Getting data works in much the same way. You can either use Services to do that, or if you can manage/don't need your own authentication see indrock's answer for a good method.

Services is very extensible, so even if the answers module doesn't implement resources, it's a pretty easy job to add your own that wrap around API functions from the answers (or any other) module.

The documentation for services would probably be a good place to start.


You'll first need to create a page(URL) in Drupal to get this parameters. You can do this by implementing hook_menu(), in your custom module. Refer this to create your custom module.

function MYMODULE_menu() {
  $items['get_details'] = array (
    'title' => '',
    'page callback' => 'MYMODULE_access_variables',
    'page arguments' => array(1),
    'access callback' => TRUE,  // this will be accessible to everyone
  return $items;

function MYMODULE_access_variables() {
 // Here you get access to the POSTED variables using $_RESPONSE php superglobal
  echo "<pre>";
  print_r ($_RESPONSE['title']);  // will get you the value of the HTML input type having name='title'
  echo "</pre>"

This will create a page at your site at url http://mydrupalsite.com/get_details

Now, from your HTML do the calling like

<form action="mydrupalcite.com/get_details" method="post">
    <input type="text" name="title" /> <!-- Note that the value of the attribute 'name' will be used the capture the value which is posted -->

NOTE: As per @clive's answer, I'd suggest you use it only for development/educational purpose. This might have security implications.

  • 1
    print_r will PRINT the given parameters to your site. If you want Drupal to add the rest of the page (sidebars, css, etc), use something like this:pastebin.com/TC1FfPY7
    – AKS
    Sep 7, 2012 at 15:25
  • @AyeshK Nice suggestion! I just printed the value just to show that the values could be accessed inside the function :)
    – AjitS
    Sep 7, 2012 at 15:28

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.