第二个表单提交捕获问题-PHP

第二个表单提交捕获问题-PHP,php,Php,您好,有人能给我一个线索,为什么“Form 2 is here”(表格二在此)信息没有显示在下面的代码中?我已经用下面的结构编写了一段很长的代码。谢谢你的帮助 <DOCTYPE html> <html> <head><title></title> </head> <body> <div id="one" style="width:300px; background:gray;"> <form m

您好,有人能给我一个线索,为什么“Form 2 is here”(表格二在此)信息没有显示在下面的代码中?我已经用下面的结构编写了一段很长的代码。谢谢你的帮助

<DOCTYPE html>
<html>
<head><title></title>
</head>
<body>
<div id="one" style="width:300px; background:gray;">
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<input type="text" name="txt1" id="txt1">
<input type="submit" name="sendone" id="sendone" value="One">
</form>
</div>

<div id="two" style="width:300px; background:yellow;">
<?php
if(isset($_POST['sendone']))
{echo "<input type='submit' name='sendtwo' id='sendtwo' value='Two'>";}

if(isset($_POST['sendtwo']))
{echo "Form two is here!"; return;}
?>
</div>
</body>
</html>


在表单中,您只有一个字段“sendone”。另一个放置在窗体外部

提交第一个表单后,将在HTML代码中插入第二个输入字段,但将其放在表单标记之外。这就是为什么当您第二次提交表单时,它不在请求中的原因。所有输入字段都应位于开始和结束表单标记内,以便进行处理

您应该将第二个表单输入放在“表单”标记中:

<DOCTYPE html>
<html>
<head><title></title>
</head>
<body>
<div id="one" style="width:300px; background:gray;">
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<input type="text" name="txt1" id="txt1">
<?php
if(isset($_POST['sendone']))
{echo "<input type='submit' name='sendtwo' id='sendtwo' value='Two'>";}
?>
<input type="submit" name="sendone" id="sendone" value="One">
</form>
</div>

<div id="two" style="width:300px; background:yellow;">
<?php
if(isset($_POST['sendtwo']))
{echo "Form two is here!"; return;}
?>
</div>
</body>
</html>


sendtwo不在表单中,也没有名为sendtwo的表单提交按钮

<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
    <input type="text" name="txt1" id="txt1">
    <input type="text" name="sendtwo" value="I am sendtwo!">
    <input type="submit" name="sendone" id="sendone" value="One">
</form>

因为
sendtowo
不属于该表单。@Baba我建议您完整地阅读该行,我真诚地希望您能理解英语。“我已经用下面的结构写了一段很长的代码”谢谢@stefandoorn!