我为不同的提交按钮设置条件


isset condition for different submit button

我有两个提交按钮在我的网页。一旦按钮被点击(使用post方法),它将执行不同的操作。

如何检查用户单击了两个按钮中的哪一个?

两个按钮的代码

<form name="existingForm" method="post" action="">
     <div class="alert alert-info" role="alert" style="text-align: center;">
          <label>Are you a returning customer?</label>
          <input name="button1" type="submit" value="Login Here" />
     </div>
</form>
<form name="logingForm" method="post" action="">
     <div class="alert alert-info" role="alert" style="text-align: center;">
          <label>Are you a returning customer?</label>
          <input name="button2" type="submit" value="Login Here" />
     </div>
</form>
按钮1的post方法代码:
if($_SERVER["REQUEST_METHOD"] == "POST")
    {
        $buttonPressed = 1;
    }
按钮2的post方法代码:
if($_SERVER["REQUEST_METHOD"] == "POST")
    {
        $buttonPressed -= 1;
    }

为什么不检查各自的button是否按下,然后做你的东西?比如:

<?php
if(isset($_POST['button1']))
{
// your stuff for existingForm
}
else 
if(isset($_POST['button2']))
{
// your stuff for logingForm
}
<form name="existingForm" method="post" action="">
     <div class="alert alert-info" role="alert" style="text-align: center;">
          <label>Are you a returning customer?</label>
          <input name="button1" type="submit" value="Login Here" />
     </div>
</form>
<form name="logingForm" method="post" action="">
     <div class="alert alert-info" role="alert" style="text-align: center;">
          <label>Are you a returning customer?</label>
          <input name="button2" type="submit" value="Login Here" />
     </div>
</form>