两个提交相同表单的按钮

时间:2015-02-26 10:36:02

标签: php html

Lets说我有表格,最后我有2个按钮

1 - 发送测试表格

2 - 发送实时表格

都发送相同的表格。如何将参数发送到服务器,以便我知道它的测试是否存在?

由于

<form method='post' action='index.php?page=mailing&amp;campID=<?PHP echo $_GET['campID'] ?>&amp;act=<?PHP echo $actType ?>' id="Form" >     
    <table class="sort">
        <tr>
            <td>email address</td>
            <td><input type="text" name="emailTest" value="<?PHP echo $user_details['email'] ?>" /></td>
        </tr>
        <tr>
            <td></td>
            <td><a href="#" class="button3d" onClick="document.getElementById('Form').submit()">send test</a></td>
            <td><a href="#" class="button3d" onClick="document.getElementById('Form').submit()">send live</a></td>
        </tr>
    </table>
</form>

2 个答案:

答案 0 :(得分:2)

只需检查php是否提交&#39;字段是测试&#39;或者&#39;生活&#39;。

<form method='post' action='' id="Form" >     
    <table class="sort">
        <tr>
            <td>email address</td>
            <td><input type="text" name="emailTest" value="" /></td>
        </tr>
        <tr>
            <td></td>
            <td><button type="submit" name="submit" value="test">Test</button></td>
            <td><button type="submit" name="submit" value="live">Live</button></td>
        </tr>
    </table>
</form>

答案 1 :(得分:0)

您需要使用JS,或者一个提交按钮和一个单选按钮。后者是一个更好的选择,因为你不能不小心提交错误的队列。此外,您应该使用提交按钮,而不是锚点。

我更喜欢单选按钮的原因是因为一旦你点击提交,你就会超越不归路。单选按钮允许您单击错误的按钮,然后进行更改。

input[type="submit"] {
  background: none;
  border: 0;
  color: blue;
  text-decoration: underline;
  cursor: pointer;
}
<form method='post' action='' id="Form">
  <table class="sort">
    <tr>
      <td>email address</td>
      <td>
        <input type="text" name="emailTest" value="" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="testLive" value="test" id="test" />
        <label for="test">Submit as Test</label>
      </td>
      <td>
        <input type="radio" name="testLive" value="live" id="live" />
        <label for="live">Submit as Live</label>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="submit" value="Submit" />
      </td>
    </tr>
  </table>
</form>

相关问题