使用PHP脚本在POST中发送错误的提交按钮

时间:2018-06-09 14:52:06

标签: php html forms

我的PHP表单使用了多个我用于A / B处理的提交按钮

偶尔,错误的提交按钮会被传递,即使它们不是点击的按钮。按钮看起来像这样:

<form method="post" action="url..." autocomplete="off">
... fields...
<input type="submit" name="UpdateExit" value="Exit" />
<input type="submit" name="UpdateSave" value="Save" />
<input type="submit" name="InsertNew" value="Insert new" />
<input type="submit" name="Delete" value="Delete" />            
<input type="button" name="Cancel" value="Cancel" />
</form>

有时,var_dump($_POST)同时显示UpdateExitUpdateSave ,即使我点击了InsertNew!不用说它搞砸了输出。然后&#34;右键&#34;已发送。

我将此行为缩小到webkit浏览器,并且在清除浏览器缓存后第一次使用该表单时,它似乎恢复正常&#34;。这是经验性的,我不能说它与PHP或HTML有关。但是我在这一天的大部分时间里一直在努力解决这个问题,并且在SO或其他地方找不到关于信息的信息:(

有人听过/遇到过类似的行为吗?

1 个答案:

答案 0 :(得分:0)

尝试:

<form method="post" action="url..." autocomplete="off">
... fields...
<input type="submit" name="UpdateExit" value="Exit" />
<input type="submit" name="UpdateSave" value="Save" />
<input type="submit" name="InsertNew" value="Insert new" />
<input type="submit" name="Delete" value="Delete" />            
<input type="submit" name="Cancel" value="Cancel" />
</form>

像处理任何其他提交按钮一样处理取消逻辑。

PHP表单处理程序逻辑:

<?php
    if (isset($_POST['UpdateExit'])) {
        //Do something based on Update and Exit was used
    }
    elseif (isset($_POST['UpdateSave'])) {
        //Do something based on Update and Save was used
    }
    elseif (isset($_POST['InsertNew'])) {
        //Do something based on Insert New was used
    }
    elseif (isset($_POST['Delete'])) {
        //Do something based on Delete was used
    }
    else {
        //Do something because Cancel was used...
    }
?>