I need to update a text box on my HTML form with a variable returned from a regex search in a function...
I can echo out the value within the function which works fine and contains the right info...
just cant work out how to set the text box to that value...
heres my code:
Its the MAC text box i want to populate with either the $mac[1] or $macadd...
Code: Select all
$form =
"
<body>
<form method='post' action='aaa.php'>
<div id='Info'>
<input name= 'MAC' type= 'text' value= '$macadd'>
<input type= 'submit' name= 'info' value='info'>
</div>
</body>
";
if (isset($_POST['info']))
{
$xml = "";
$method = "GET";
$posttxt = "/DeviceInformation";
sendXML($xml,$posttxt,$method);
}
function sendXML($xml,$posttxt,$method)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$auth = base64_encode($userid.":".$pin);
$xml = "XML=".urlencode($xml);
$post = $method." ". $posttxt. " HTTP/1.0\r\n";
$post.="Host: $ip\r\n";
$post.="Authorization: Basic $auth\r\n";
$post.="Connection: close\r\n";
$post.="Content-Type: application/x-www-form-urlencoded\r\n";
$post.="Content-Length: ".strlen($xml)."\r\n\r\n";
$response = "";
$sock = fsockopen($ip, 80, $errno, $errstr, 30);
if ($sock)
{
fwrite($sock, $post . $xml);
while (!feof($sock))
{
$response .= fgets($sock, 128);
}
fclose($sock);
}
if (strpos($response, 'Status="0"') !== false)
{
echo 'Authenticated<BR>';
}
if(preg_match(
'@MAC Address</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$mac
))
{
$macadd=$mac[1];
}
else{echo $response;}
}