• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: silent post/ retrieving json from external api

silent post/ retrieving json from external api 12 years 7 months ago #14906

  • sazqatch
  • sazqatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 1
Hi. Im trying to incorporate an API from my client which returns a json string after posting to an https url.

Ultimate Goal:
1. user fills out short form
2. I send post to API url which returns json string
3. I parse json srting and display output on the screen
4. (optional) after user sees output they have option to enter more info. I was hoping I could do this with a multipage form, but im not sure. Is there a way to have this call done on the "next" field?

So, im researching the script form fields in the rsform pro. I tested this in the top field (called on form display) and it does the alert before showing the form. This was just for testing. I tried this in the other 2 script fields but does not produce an alert.

print '<script type="text/javascript">';
print 'alert("111111")';
print '</script>';

So i then found this link from rsjoomla on silent posting. Im hoping this is the direction i need to go.
www.rsjoomla.com/support/documentation/v.../83-silent-post.html

The API documentation supplied gives me the following info: "rates can be obtained by POSTing your request parameters over https to rate.honestpolicy.com/get_rates. The encoding/content-type to be used is "application/x-www-form-urlencoded". The rest of the api doc describes the specific var names.

The code below is what i got from the above link. I tried to simply echo the result var, but that doesnt seem to work. should i try to be displaying the vars in the results email? will they be avail as $_POST ??

Any guidance will be appreciated. Thanks!!

// this is your form's action URL
$url = 'rate.honestpolicy.com/get_rates';

$ch = curl_init();

// set user agent
$useragent = 'YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; search.yahoo.com/)';
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// don't touch this
curl_setopt($ch, CURLOPT_POST, 1);

// set the target URL which contains scripts that accepts post request
curl_setopt($ch, CURLOPT_URL, $url);

// set the variables to be sent
// the format of the variables is var1=value1&var2=value2&var3=value3
$data = array();
foreach ($_POST as $post => $value)
{
if (is_array($value))
foreach ($value as $post2 => $value2)
$data[] = $post.'[]='.urlencode($value2);
else
$data[] = $post.'='.urlencode($value);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));

// execute curl,fetch the result and close curl connection
$result = curl_exec($ch);
curl_close($ch);

// my attempt to display results
echo $result;
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!