我有一个带有提交按钮的html。Submit会将您发送到php。
php代码有这样的:
header("location:./setupOk.html");
$html = file_get_html('setupOk.html');
$ret = $html->find('div[id=valueOk]');
echo $ret[0]->innertext = "foo";
这是我的一些html setupOk.html代码:
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
在第一个html上执行按钮后,它转到php并用setupOk重新加载我的html网站,但任何地方都没有文本。有什么解决方案吗?
编辑:我的目标是拥有一个通用的html(带有标签和图像),然后从php中,将文本放入该html中,并自动将该html加载到用户的浏览器上
第2版:我的第一个HTML和第二个HTML不一样。首先将申请发送到PHP,然后根据发送到PHP的信息,PHP将在第二个HTML中填充文本,并将最后一个HTML加载到用户的浏览器上
避免DOMParser
和加载/重定向到HTML
页面——您可以用更简单的方式来完成,比如(它必须是PHP
文件):
<?php
$innerText = "";
if (!empty($_POST['Key'])) {
$innerText = "foo";
}
?>
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" value="<?php echo $innerText;?>"/>
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
如果您认为这不是您想要的,请详细说明您的需求。
更新
setupOk.php
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
keys.php[提交表单的位置]
require_once('simple_html_dom.php');
$processedResult = "";
if (!empty($_POST['Key'])) {
$processedResult = "foo";
}
$html = file_get_html('setupOk.php');
$html->find('input[id=valOk]', 0)->value = $processedResult;
echo $html;
我已经测试过了,它正在发挥作用。