Php POST方法中确定表单ID的一种方法

Php POST方法中确定表单ID的一种方法,php,html,Php,Html,我想知道是否能够以任何方式确定发布在PHP上的表单的ID <form id="ES1A" action="enroll.php" method="post"> <input type="checkbox"/> <button type="submit" class="btn btn-primary">Next Step</button> </form> 附言:我不太确定如何在PHP上实现这一点。提前感谢Post不使用元素的ID,而是名

我想知道是否能够以任何方式确定发布在PHP上的表单的ID

<form id="ES1A" action="enroll.php" method="post">
<input type="checkbox"/>
<button type="submit" class="btn btn-primary">Next Step</button>
</form>

附言:我不太确定如何在PHP上实现这一点。提前感谢

Post不使用元素的ID,而是名称,因此您可以使用

<form name="ES1A" action="enroll.php" method="post">
    <input type="checkbox"/>
    <input name="formid" value="ES1A" /><!-- This holds your form id so you can use this -->
    <button type="submit" class="btn btn-primary">Next Step</button>
</form>

如果窗体的“名称”属性不起作用,则始终可以为按钮设置名称:


另一种方法是使用隐藏输入

 <input name="ES1A" value="formid" type="hidden" />


您是否可以添加一个隐藏的输入并将表单ID放入该值中?只需使用一个隐藏的输入字段,并将表单ID作为值,我相信没有更好的方法。没有(没有手动解决方法)。但这听起来像是个XY问题。你为什么要这样做?@jeff我想让多个表单重定向到同一个.php文件。。你说的“XY问题”是什么意思。。但是,如果有一种不添加隐藏表单的方法来实现这一点不是更有效吗?我几乎不相信表单的名称不会通过提交来发送。如果我错了,请纠正我。我也不太确定,这不是不可能的,但这只是为了使用OP的示例:)谢谢您的输入:)我现在要用它。。但我真的在寻找那种方法。。(如果它甚至可能的LOL)@死亡-如果这解决了问题,请考虑点击这个滴答声,这样用户知道你已经找到了解决方案,否则人们将不知道:“你说的“PHP部分应该是一样的”是什么意思?提供一个例子。与OP的例子相同
if (isset($_POST['ES1A']) // Unsure if form itself will be posted with the submit
{
    // This is set as it uses the name of the element
    $formid = $_POST['formid']; // Get the ID of the form from the element passed in
}
<button name="ES1A" type="submit" class="btn btn-primary">Next Step</button>
<input name="ES1A" type="submit" class="btn btn-primary" value="Next Step">
if(isset($_POST['ES1A']))
{
  //Code after checking that the form that was submitted indeed has the ID of ES1A
}
 <input name="ES1A" value="formid" type="hidden" />