Form to URL, XML Returned - Need Help
All that just to get some data back? There has to be an easier way. If I submit the form data using the form, can I catch an http return with the XML or something?
Is the processing script that you're submitting your form data to on your server? If not, then when the form is submitted you'll be leaving your website. If you use cURL you can send the form data to the script and capture the response. It's really not all that difficult:
$ch = curl_init("http://www.theurl.com/Results.ASP&a=1&b=2");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
You may need to set additional options.
You are right, thanks! Will give it a try.
hmmm, all i get is a blank page....
Make sure that you're displaying errors. If you can create your own .htaccess file or php.ini file make sure that display_errors is set to on and error_reporting is set to 6135.
all i get is a blank page....
$ch = curl_init();
$pData = array('UserId'='myID','Password'='myPass','Return'='XML','Client_Reference'='ddfde','SearchType'='business','Name'='JohnNidder','Business_Name'='Highway','Street_Number'='8890','Street_Name'='Driscoll','City'='Seattle','State'='WA','ZIP'='98110');
curl_setopt($ch, CURLOPT_URL, "http://myURL/Results.ASP");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
print_r($output);
if you are trying to access a page on another server and you want to use cURL, you need the cURL package at this website. alternately, you could try to use ftp which would be built-in if you have windows on your server, but will need installation if you are on a linux system. But if you choose to stick with cURL go to this website for a full list of requirements.
$output = curl_exec($ch);
if (curl_errno($ch) !== 0) {
echo curl_errno($ch) . ': ' . curl_error($ch);
}
else {
// ...
}
OK! Thanks for the help. I have cURL working and am receiving the XML below. Yeah!
How can I take that and manipulate it? Can I make an object out of it and then iterate through the object and display the various values? Thank you!!
<data><results/><info><query><field name="Business Name">Highway 20</field><field name="Filing Number">00000</field><field name="Name">Erik Clineschmidt</field><field name="Street #">8890</field><field name="Street Name">Driscoll Lane NE</field><field name="City">Bainbridge Island</field><field name="State">WA</field><field name="ZIP Code">98110</field></query><search_time units="seconds">0</search_time><clientReference>ddfde</clientReference></info></data>
Good to hear. Now is when Simple XML comes in to play. Something like this (untested):
$string = '<data><results/><info><query><field name="Business Name">Highway 20</field><field name="Filing Number">00000</field><field name="Name">Erik Clineschmidt</field><field name="Street #">8890</field><field name="Street Name">Driscoll Lane NE</field><field name="City">Bainbridge Island</field><field name="State">WA</field><field name="ZIP Code">98110</field></query><search_time units="seconds">0</search_time><clientReference>ddfde</clientReference></info></data> ';
$xml = simplexml_load_string($string);
foreach($xml->info->query->field as $field){
echo $field . "\n";
}
Thank you. Looks like that would work, but I'm getting:
Warning: Invalid argument supplied for foreach() in /home2/corpsurf/public_html/developer/cURL.php on line 53
ok, i figured it out. was my error. guess i need to work on parsing a simplexml object.....
OK, good. I just tested what I wrote and it worked as expected. Remember to skip the root node.
looks like im getting multiple objects instead of one from $string, doesnt it:
object(SimpleXMLElement)#1 (2) { ["results"]=> object(SimpleXMLElement)#4 (0) { } ["info"]=> object(SimpleXMLElement)#3 (3) { ["query"]=> object(SimpleXMLElement)#2 (1) { ["field"]=> array(8) { [0]=> string(10) "Highway 20" [1]=> string(5) "00000" [2]=> string(17) "Erik Clineschmidt" [3]=> string(4) "8890" [4]=> string(16) "Driscoll Lane NE" [5]=> string(17) "Bainbridge Island" [6]=> string(2) "WA" [7]=> string(5) "98110" } } ["search_time"]=> string(5) "0.016" ["clientReference"]=> string(5) "ddfde" } }
is that the expected result?
I'm pretty sure that you can still traverse through the objects as I already showed you. But if you're expecting something other than what your getting, let us know what it is you're aiming for.
deleted by author. going to keep at it.
See if this works.
<?php
$string = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<results/>
<info>
<query>
<field name="Business Name">Highway 20</field>
<field name="Filing Number">00000</field>
<field name="Name">Erik Clineschmidt</field>
<field name="Street #">8890</field>
<field name="Street Name">Driscoll Lane NE</field>
<field name="City">Bainbridge Island</field>
<field name="State">WA</field>
<field name="ZIP Code">98110</field>
</query>
<search_time units="seconds">0</search_time>
<clientReference>ddfde</clientReference>
</info>
</data>
XML;
$xml = simplexml_load_string($string);
var_dump($xml);
?>
and check the example out for yourself (if you want) here.
sorry about that last post. I was looking at a problem you had last page. disregard what i said. that wont help you now.