This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Using HttpClient.class.php: How to get JSON response?


  1. alexjames01
    Member

    I am using HttpClient.class.php to pass info to a social network API (wildfire) to sign up users on that network via one of my forms... I need to get the JSON response and parse part of it to redirect from one of the MachForms.

    An example JSON response would be:

    ---------

    {
    "id": "72e334df-5d35-4ca0-bcba-49fb4d2070e2",
    "loginUrl": "http://yourwildfiredomain.com/securi...c-afe367ac17fa",
    "password":"zODqFbeN"
    }

    ---------

    I need to catch the loginUrl and redirect them on form submission.

    Here is the code I am using (starting line 1183 on post-functions.php)

    ---------

    if($form_id == 1 || $form_id = 3){
    $target_url = 'http://****.wildfireactionnetwork.com/api/users';

    // SEND WILDFIRE API KEY
    $target_data['apiKey'] = "****";

    // SEND WILDFIRE THE FULL NAME

    $firstnm = $table_data['element_1_1'];
    $lastnm = $table_data['element_1_2'];
    $fullnametmp = $firstnm . " " . $lastnm;

    $target_data['fullName'] = $fullnametmp;

    // SEND WILDFIRE THE EMAIL
    $target_data['email'] = $table_data['element_2'];

    require 'lib/HttpClient.class.php';

    $pageContents = HttpClient::quickPost($target_url, $target_data);
    }

    -------

    Posted 15 years ago #
  2. yuniar

    Try this:

    $pageContents = HttpClient::quickPost($target_url, $target_data);
    require('includes/JSON.php');
    
    $json = new Services_JSON();
    $wildfire_response  = $json->decode($pageContents);
    
    $response_id = $wildfire_response->id;
    $response_loginUrl = $wildfire_response->loginUrl;
    $response_password = $wildfire_response->password;

    MachForm Founder

    Posted 15 years ago #

RSS feed for this topic

Reply