phpnode.jsdrupaldrupal-7drupal-form-submission

Send Data from Drupal to node.js


I'm a newbie with drupal.

I was trying to send data from drupal to node.js function and save the data from node into mongo.

I wrote a function in php

function sample_working_submit($form, &$form_state) { //Function to connect with node and save into Mongo using node
  $Name = check_plain($form_state['values']['Name']);
  $Age = check_plain($form_state['values']['Age']);
  $request_url = "http://10.20.5.112:3001/save/$Name/$Age ";
  $response = drupal_http_request($request_url);
}

This is working as long as there is no 'space' between the names(input). How can save the input with spaces.Why does this issue came?

How can i rewrite the function as post?


Solution

  • <?php
    $url = http://localhost:8080/myservlet;
    
    $data = array (
        'name' => check_plain($form_state['values']['Name']),
        'age' => check_plain($form_state['values']['Age'])
        );
    
    $response = drupal_http_request($url, $headers, 'POST', json_encode($data));
    ?>
    

    This would POST data to URL. Note that you need to change logic in server side as well to receive POST data instead of GET data.

    Refer here for more info