Jump to content

Recommended Posts

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

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

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?

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;
?> 

 

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.

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.

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

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.

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

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

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.

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.

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.

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?

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.

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

 

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.

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

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);

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.