2

I have created a form custom module for get data from an external url.

$requestType = drupal_http_request('http://www.example.in/php/example/getSampleType.php',$options); $loomType =drupal_json_decode($requestType->data);

This is my Form enter image description here

Using this result I have created checkboxes and select a value from checkbox then submit the data.

function myForm_form_submit($form, &$form_state) {


$form_state['rebuild'] = TRUE;
$url='http://www.example.in/php/example/exampleSort.php';
//$data1 = http_build_query($form_state['values']['check'], '', '&');

$checked = array();
foreach($form_state['values']['check'] as $key => $val) {
array_push($checked, $val);
  }
$mychecked=checking($checked);

$checkedType = array();
foreach($form_state['values']['checktype'] as $key => $val) {
array_push($checkedType, $val);
  }
$loomType=checking($checkedType);

$datas=array("sampleMachine"=>$mychecked, "sampleType"=> $loomType);
$data =json_encode($datas);
$option = array(
            'method' => 'POST',
            'data' => $data,
            'headers' => array('Content-Type' => 'application/json'),
    );
//$headers = array('Content-Type' => 'application/json');

$response =drupal_http_request($url,$option);

echo "<pre>";
print_r($response);
echo "</pre>";

}

I got some result. Now I want to display those results in my drupal page. How can I do that..I am using Drupal 7.

I want to display this in Drupal page in specific format enter image description here

2
  • This question is really broad. Typically a form has a build, validation and submit functions as briefly detailed here. drupal.org/node/1419390 Then you display the results in any 1 of many ways, an example can be found in the Examples module for developers, or similar questions here: drupal.stackexchange.com/questions/54374/…
    – tenken
    Commented Apr 22, 2016 at 6:42
  • But I didnt understand how to display myresult
    – user
    Commented Apr 22, 2016 at 7:26

1 Answer 1

1

Not sure why you want to create a custom module for this, since ... there is a module that can "*display JSON results in a Drupal page" ... i.e. the Views JSON Query module. Some details from its project page:

JSON Query is a Views 3 plugin that adds native JSON query generation. It allows you to parse JSON using Views' graphical query builder. It works much like Views XML Backend but with JSON.

And a screenprint from that same page:

enter image description here

For more details, read about it in the article about "Show external JSON data in Drupal Views".

PS: Similar solution if your input format is XML (instead of JSON), using Views XML Backend.

22
  • Using this module I can create check boxes ?
    – user
    Commented Apr 22, 2016 at 7:41
  • Correct me if I'm wrong, but the equivalent of your "example form" would become an exposed filter of your view. Or am I missing something? Commented Apr 22, 2016 at 8:01
  • I have installed above mentioned modules and tried to create views. In query settings field I have added the url example.in/php/example/exampleSort.php It displaying like this { "nodes" : [ { "node" : { "value" : "" } }, { "node" : { "value" : "" } }, { "node" : { "value" : "" } } ] }
    – user
    Commented Apr 22, 2016 at 9:20
  • Your last comment really looks like a new question to me, which you shuld post as a new question. Also, looking at your profile I noticed you don't have the "informed" badge. Which is probably also why you're not aware of what's written in drupal.stackexchange.com/help/someone-answers . Commented Apr 22, 2016 at 9:40
  • Thank you for ur information. I am not able to display my Json result using Views JSON Query .
    – user
    Commented Apr 22, 2016 at 10:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.