milfone Posted October 12, 2011 Share Posted October 12, 2011 Hi, I’ve got a problem to retrieve form data from Php page that produce an XML. I’m trying to explain better. I send form data from PageA to PageB, PageB is a PHP file that produce an XML output like this: <response> <status></status> <message></ message > <id_costumer/> </response> If the form field of pageA is inputted correctly, pageB return status “OK”, message “Thank you to fill our form”, and Id_costumers “autoincremented id example 123” and the output is in XML like above. So, the problem is that the pageB is not on my server, how can I parse the Xml file and intercept the value of the above tag submitted by pageA? If I parse the XML file with direttive include like this: Syntax: [ Download ] [ Hide ] [ Select ] <?php include 'http://www.site.com/pageB.php'; $movies = new SimpleXMLElement($xmlstr); … ?> it's seems doesn't work and I can’t to retrieve any form value of the pageA. Please help me, I'm so frustrated, any suggestion will be appreciated. Thanks Ric Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/ Share on other sites More sharing options...
requinix Posted October 12, 2011 Share Posted October 12, 2011 SimpleXMLElement can pull XML from a file. Or webpage. $movies = new SimpleXMLElement("http://www.example.com/pageB.php", 0, true); Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278648 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 SimpleXMLElement can pull XML from a file. Or webpage. $movies = new SimpleXMLElement("http://www.example.com/pageB.php", 0, true); Assuming that your server has allow_url_fopen enabled, which many shared hosts do not. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278661 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 SimpleXMLElement can pull XML from a file. Or webpage. $movies = new SimpleXMLElement("http://www.example.com/pageB.php", 0, true); Assuming that your server has allow_url_fopen enabled, which many shared hosts do not. -Dan The include method works fine, but the Xml's tag is empty. Do you know why? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278735 Share on other sites More sharing options...
requinix Posted October 12, 2011 Share Posted October 12, 2011 No. Are you sure it's empty? How do you know? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278739 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 Define "xml's tag." Show what you're getting and what you're expecting. Did you view the source? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278740 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 This is the real example, If I post the form field directly to Php that produce XML page like above it works: PAGE A on my server: http://lnx.studioarletti.it/moduli/pageA.php(pageB.php is not on my server, and produce the correct XML tag). But I need to retrieve the the id_cliente/id_costumer and send it to costumer by email, and I can't to do it cause I can't include the external XML file to my php page. This is the other example and it's seems doesn't work on my server probably because there is a problem about php.ini and include direttive, but on my localhost it works and the string seems to be empty: http://lnx.studioarletti.it/moduli/pageA2.php and the code of my include file is: <?php include 'http://notmysite.com/crea_utente.php'; $response = new SimpleXMLElement($xmlstr); echo $response->id_cliente; ?> Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278749 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 This is the real example, If I post the form field directly to Php that produce XML page like above it works: PAGE A on my server: http://lnx.studioarletti.it/moduli/pageA.php(pageB.php is not on my server, and produce the correct XML tag). But I need to retrieve the the id_cliente/id_costumer and send it to costumer by email, and I can't to do it cause I can't include the external XML file to my php page. This is the other example and it's seems doesn't work on my server probably because there is a problem about php.ini and include direttive, but on my localhost it works and the string seems to be empty: http://lnx.studioarletti.it/moduli/pageA2.php and the code of my include file is: <?php include 'http://notmysite.com/crea_utente.php'; $response = new SimpleXMLElement($xmlstr); echo $response->id_cliente; ?> If there is other method to retrieve the XML tag in a php page, I think will be ok. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278752 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 My bad, this is the error: Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML So, How can I parse a php page with XML file output? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278763 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 My bad, this is the error: Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML So, How can I parse a php page with XML file output? Obviously it's not XML, that's problem #1. Since we don't have the actual XML file's location, that's all we can tell you. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278773 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 There is no way? This is the exact url of the php page http://test.interateneo.com/admin/clienti/integra/crea_utente.php and produce this xml (like wrote in first post) <response> <status></status> <message></ message > <id_costumer/> </response> There is a solution? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278775 Share on other sites More sharing options...
requinix Posted October 12, 2011 Share Posted October 12, 2011 var_dump(new SimpleXMLElement("http://test.interateneo.com/admin/clienti/integra/crea_utente.php", 0, true)); object(SimpleXMLElement)#1 (3) { ["stato"]=> string(2) "KO" ["messaggio"]=> string(18) "Parametri mancanti" ["id_cliente"]=> object(SimpleXMLElement)#2 (0) { } } Works fine for me. Copy/paste your exact code into your next post. Also, if allow_url_fopen was off then you'd be getting a different error message. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278781 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 var_dump(new SimpleXMLElement("http://test.interateneo.com/admin/clienti/integra/crea_utente.php", 0, true)); object(SimpleXMLElement)#1 (3) { ["stato"]=> string(2) "KO" ["messaggio"]=> string(18) "Parametri mancanti" ["id_cliente"]=> object(SimpleXMLElement)#2 (0) { } } Works fine for me. Copy/paste your exact code into your next post. Also, if allow_url_fopen was off then you'd be getting a different error message. Sorry but I'm new to PHP and XML, maybe I don't understand what I have to do, I'm trying to copy and past your code to my php page but I've got an error: Parse error: parse error in C:\wamp\www\moduli\xml.php on line 12 in line 12 there is this code: ["stato"]=> Can you explain what I do with an example code to retrieve the id_cliente (like $_POST in php)? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278784 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 I've seen the tutorial to create a SimpleXMLElement object from a URL, like requinix's suggestion: $sxe = new SimpleXMLElement('http://test.interateneo.com/admin/clienti/integra/crea_utente.php', NULL, TRUE); echo $sxe->asXML(); But the tag element is empty: KO Parametri mancanti and no returned id_cliente. I have to use something like XMLHttpRequest? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278786 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 Requinix posted two separate things: 1) PHP code to retrieve an XML document, parse it with simpleXML, and print the results. 2) The results of executing that PHP code. You were asked to copy and paste the first part and see if your results match the second part. You unfortunately do not know enough PHP to recognize the difference between valid code and debug output. It may be in your best interest to purchase a PHP book and work through it on your own until your proficiency is increased. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278790 Share on other sites More sharing options...
milfone Posted October 12, 2011 Author Share Posted October 12, 2011 Requinix posted two separate things: 1) PHP code to retrieve an XML document, parse it with simpleXML, and print the results. 2) The results of executing that PHP code. You were asked to copy and paste the first part and see if your results match the second part. You unfortunately do not know enough PHP to recognize the difference between valid code and debug output. It may be in your best interest to purchase a PHP book and work through it on your own until your proficiency is increased. Thanks ManiacDan, you're right I'll buy a PHP book. Thank you to explain me what I do, so the output code of vardump is: object(SimpleXMLElement)#1 (3) { ["stato"]=> string(2) "KO" ["messaggio"]=> string(18) "Parametri mancanti" ["id_cliente"]=> object(SimpleXMLElement)#2 (0) { } } What I do next? I really appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278794 Share on other sites More sharing options...
requinix Posted October 13, 2011 Share Posted October 13, 2011 Depends. What do you want to do? And before you say you want an ID number or something: there is no such thing in the XML. It's just not there. You probably haven't sent the right information to that crea_utente.php service. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278803 Share on other sites More sharing options...
milfone Posted October 13, 2011 Author Share Posted October 13, 2011 It works but I can't send form data to Url define in the in SimpleXMLElement: <?php $source = "http://test.interateneo.com/admin/clienti/integra/crea_utente.php"; $sitemap = new SimpleXMLElement($source,0,true); echo $_REQUEST['ds_nome']; //return correct form field echo $sitemap->stato; //stato is KO, because ds_nome not correctly submitted to above url ?> How can I send my forms data to $source, then return correct tag in the same page like id_cliente or stato? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278805 Share on other sites More sharing options...
milfone Posted October 13, 2011 Author Share Posted October 13, 2011 Depends. What do you want to do? And before you say you want an ID number or something: there is no such thing in the XML. It's just not there. You probably haven't sent the right information to that crea_utente.php service. If you try to fill this form: http://lnx.studioarletti.it/moduli/pageA.php there is a returned id_cliente number. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278806 Share on other sites More sharing options...
milfone Posted October 13, 2011 Author Share Posted October 13, 2011 This is the scenario: the form pageA.php sent data on this page http://www.externalsite.com/crea_utente.php' and if this fields are correct <form action="<URL>" method="POST"> <input type="hidden" name="ds_nome" value=""/> <input type="hidden" name="ds_cognome" value=""/> <input type="hidden" name="ds_rag_soc" value=""/> <input type="hidden" name="ds_email" value=" "/> <input type="hidden" name="ds_codfisc" value=""/> <input type="hidden" name="_utente_username" value="" /> <input type="hidden" name="_utente_password" value="" /> <input type="submit" value="Invia" name="Invia"/> </form> response with XML output: <response> <status>OK</status> <message>registration success</ message > <id_costumer/>1132132123121 </response> How I can retrieve id_costumer of XML output and send to me by email? I've tryed with SimpleXML like suggested in this topic, but in the list of Functions there isn't nothing function to send form data through a php page (crea_utente.php) that create an XML. Please help me. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278939 Share on other sites More sharing options...
ManiacDan Posted October 13, 2011 Share Posted October 13, 2011 As I suspected, that's not valid XML. There is no content in the id_costumer tag. Whatever produces this XML needs to be rewritten. You cannot use any XML parsing tools for this document, because it's not XML. I recommend regular expressions I guess. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278973 Share on other sites More sharing options...
milfone Posted October 13, 2011 Author Share Posted October 13, 2011 As I suspected, that's not valid XML. There is no content in the id_costumer tag. Whatever produces this XML needs to be rewritten. You cannot use any XML parsing tools for this document, because it's not XML. I recommend regular expressions I guess. I can't understand why, id_cliente/id_costumer return a valid id if the form was filled correctly http://lnx.studioarletti.it/moduli/pageA.php You say that beacasue id_cliente hasn't close tag? Or why? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1278999 Share on other sites More sharing options...
requinix Posted October 13, 2011 Share Posted October 13, 2011 First things first: check that the XML being returned is valid. I think you just typed some example there and didn't quite get it right. If you have to POST data to the page then you need an alternate method. Easiest is probably using cURL and $xml = new SimpleXMLElement($string_from_curl, 0, false); Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1279035 Share on other sites More sharing options...
milfone Posted October 13, 2011 Author Share Posted October 13, 2011 First things first: check that the XML being returned is valid. I think you just typed some example there and didn't quite get it right. If you have to POST data to the page then you need an alternate method. Easiest is probably using cURL and $xml = new SimpleXMLElement($string_from_curl, 0, false); How can I check if the XML is valid if I've got only the external URL to PHP file that produce XML? If I use Curl what I have to put on variable $string_from_curl? How can I use Curl in combination with SimpleXMLElement? Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1279056 Share on other sites More sharing options...
requinix Posted October 13, 2011 Share Posted October 13, 2011 How can I check if the XML is valid if I've got only the external URL to PHP file that produce XML? Fill out and submit the form yourself. You said the thing returns XML, right? Look at the XML you get back. It that's invalid then there are problems. If I use Curl what I have to put on variable $string_from_curl? The response you get from using cURL. How can I use Curl in combination with SimpleXMLElement? In this case, you use cURL to submit POSTed form information to a page and get the XML result back as a string. Then you give it to SimpleXMLElement like in the code I gave. Do some research. Start here. Quote Link to comment https://forums.phpfreaks.com/topic/248966-problem-to-retrieve-form-data-from-xml-page/#findComment-1279059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.