【发布时间】:2020-11-15 16:56:10
【问题描述】:
我有这个 php 脚本,它根据从另一个表单发送的数据提交一个表单。 这是我的代码:
function test($param)
{
// second form
echo "<form action='' method='post'>
<input class='btn btn-primary' type='submit' value='test' name='test$param'>
</form>";
if(isset($_POST["test$param"]))
{
echo "true";
}
}
function test1()
{
return 4;
}
function test2()
{
for($x = 0; $x <= test1(); $x++)
{
test($x);
}
}
// first form
echo "<form action='' method='post'>
<input type=radio class=form-check-input value=opt1 name=opt1>opt1
<input type=radio class=form-check-input value=opt2 name=opt2>opt2
<input type=submit value=Submit name=submit>
</form>";
if(isset($_POST["submit"]) && isset($_POST["opt1"]))
{
test2();
}
当我提交第一个表单时,会显示第二个表单,但问题是 if(isset($_POST["test$param"]) 语句返回 false(当我提交第二个表单时,没有打印 true)。
为什么会这样?
【问题讨论】: