Page 1 of 1

sending xml data in a hidden field of a php form via post

Posted: Sat Feb 11, 2006 11:12 pm
by marta bau
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


hi to all,
i have this page data.php

page data.php:

Code: Select all

<?
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $_POST["datos"], $vals, $index);
xml_parser_free($xml_parser);

$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}

$datos = $params["NOTIFICACIONXML"];

// here i want to show the data sent by another php file that you can check below

?>
what i need is to modify the script data.php above to be able to get the data sent by the script that you can ckeck below, this script just send xml data in a hidden input via post when the page is loaded:
script that sends data to data.php:

Code: Select all

<?php

$strFormulariAction = "data.php";

$Ds_url = "web";
$Ds_url1 = "web1";
$Ds_url2 = "web2";
$Ds_url3 = "web3;

$strEntrada = "<DATOSENTRADA>";
$strEntrada .= "<DS_VERSION>1.0</DS_VERSION>";
$strEntrada .= "<DS_MERCHANT_URL>" . $Ds_url . "</DS_MERCHANT_URL>";
$strEntrada .= "<DS_MERCHANT_URL1>" . $Ds_url1 . "</DS_MERCHANT_URL1>";
$strEntrada .= "<DS_MERCHANT_URL2>" . $Ds_url2 . "</DS_MERCHANT_URL2>";
$strEntrada .= "<DS_MERCHANT_URL3>" . $Ds_url3 . "</DS_MERCHANT_URL3>";
$strEntrada .= "</DATOSENTRADA>";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Sen data to data.php</TITLE>
<META NAME="Generator" CONTENT="">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<form name="data" method="post" action="<?=$strFormulariAction?>">
<input type="hidden" name="entrada" value="<?=$strEntrada?>">
</form>

<script type="text/javascript">
<!--
document.forms['data'].submit();
//-->
</script>
</BODY>
</HTML>
thanks to all


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Feb 11, 2006 11:36 pm
by timvw
The following seemed to work when i needed it:

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $xml = file_get_contents('php://input');

  // do something with posted xml here...
}
?>