I have the following php and wish to know how I can achieve that the bottom part of the script is rerun with the new input value when the submit button is clicked.
I feel that my script needs just a final touch, but when you think another approach is preferred then don’t refrain from making suggestions.
I do know how to assign a javascript to a button but here I wish to rerun only the bottom code (creating soap client, calling soap web service and applying xslt to the resulting XML) and wish to have that in php (mainly because I don’t know the equivalent in ECMA script but also because the script takes care of placing the resulting table on the spot I wish to have it).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Get element details</title>
<style type="text/css">
@import url("Swift.css");
</style>
</head>
<body>
<br/>
<?php # httpCallExample2.php
echo '<form action="httpCallExample2.php" method="post">
<fieldset>
<legend>Get element details</legend>
<p>
Element: <input name="element" type="text" size="12" maxlength="12" /> <button type="submit" name="submit" value="update">Get details</button>
</p>
</fieldset>
</form>
';
echo '<br/>';
$soapReq = new SoapClient('http://www.webservicex.net/periodictable.asmx?WSDL');
$input = array ("ElementName" => $element);
$result = $soapReq ->
__soapCall("GetAtomicNumber",
array(
'parameters' => $input
)
);
$XML = new DOMDocument();
$XML -> loadXML ( $result -> GetAtomicNumberResult );
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL -> load('showResults.xslt');
$xslt -> importStylesheet( $XSL );
echo $xslt -> transformToXML( $XML );
?>
</body>
</html>
Don’t mind about the css file (that contains just some table layout stuff) but here’s the xslt I use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<table>
<thead>
<tr>
<th colspan="2">SOAP results</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="//NewDataSet/Table/*">
<tr>
<td><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
The resulting page should look something like

Where I expect the bottom part to be filled after the input element has been given the value Carbon and the submit button has been clicked.
I had hoped that someone would help me out, but as always I could not leave it alone and went on to try to find a solution.
And I did: the trick is to reopen the php file and pass the element value to it, accessible by using the expression $_POST[‘element’] (or $_GET[‘element’], when using get method instead of post).
The end result that I reached was the following:
resulting in just the input form first, and when entering (for example)
potassiumand clicking the button, this givesof course, it is possible to enter the posted value into the input element again.