2

I have created a plain HTML page. I want that the when ever a submit button is clicked, It submits the values to a form that is present on a drupal Site. Its a simple form with only text field. Any idea ?

1
  • Maybe I'm wrong, but it sounds as if you are trying to use Drupal while learning as little as possible about how Drupal works. It's like you're leaning against Drupal instead of building on top of it. That approach may work for a while, but it will get you into trouble in the long term. If you tell us which problem you're solving, we can help you solve it "the Drupal way". Oct 20 '11 at 22:03
7

A form directly can not be posted to Drupal. But a general callback can receive post request data and can process it to store it somewhere.

For this, a hook_menu entry is required to register a callback with a newly created URL . This callback can access $_POST.

On the other hand post request to Drupal can be invoked with form data either by CURL or jQuery.ajax()

Your custom module:

function hook_menu(){
  return array(
     'path/to/submit/post/values' => array(
        'title' => 'Catch Post Data',
        'access arguments' => array('access content'),
        'page callback' => 'catch_post_data',
        'type' => MENU_CALLBACK,
     ) 
  );
}

function catch_post_data(){
   $values = $_POST;
   // Get post values and store where you like.
   // Do not break the system. Do it carefully using proper entity functions.
   if($success)
       drupal_json(array('status' => 'SUCCESS'));
   else
       drupal_json(array('status' => 'FAILURE'));
}

Form can be posted via jQuery.

$.post('path/to/submit/post/values', $('#form').serialize(), function(response){
    response = $.parseJSON(response);
    if(response.status == 'SUCCESS')
        alert('Congrats!');
    else
        alert('Something went wrong');
});
3

if your form is very simple you might be able to use the prepopulate module. For example the URL to prefill a title on a blog is:

    http://www.example.com/node/add/blog?edit[title]=this is the title

Your form would submit with the "get" method to:

http://www.example.com/node/add/blog

if your form field name is "edit[title]" this should work.

1

For some security and internal process it seems pretty difficult to do it, or even impossible. You must replicate the exactly HTML form Drupal produces.
The main problem is Drupal cache, how Drupal produces a form, and the tokens Drupal adds to be sure it doesn't receive forget data, but data really submitted from a human being using a Drupal form.

I think that you've to use a proxy or create the form directly with Drupal.

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.