0

我有两个 PHP 文件,我们称它们为 fileOne.php 和 fileTwo.php。如果 fileOne.php 有一个带有action="fileTwo.php"按钮 button1 和 button2 的表单,我如何检查 fileTwo.php 是否isset($_POST['button1'])被推送或被isset($_POST['button2']推送。

这是“fileOne.php”中“fileTwo.php”的形式:(execute.php = fileTwo.php)

< form action="execute.php" method = "POST">
< input type="hidden" name="edit" value="Edit"/>
< input type="hidden" name="delete" value="Remove"/>
< /form>

这些是在 "fileOne.php" 中创建的按钮,但格式为 action= "fileTwo.php" : ("button1 = edit, button2 = delete)

echo "<td><input type='submit' name='Edit' value='Edit'>
<input type='submit' name='Delete' value='Remove'></td>\n";

如果按下任一按钮,我将在此处尝试检查“fileTwo.php”:

    //if edit is clicked
if(isset($_POST['edit'] == 'Edit'))
{
    echo"hello";
}
//if remove is clicked
if(isset($_POST['delete'] == 'Remove'))
{
    echo"good bye";
}

我会欣赏 PHP 中的解决方案,而不是 JavaScript、AJAX 等。

4

2 回答 2

2

像这样重写它:

文件一.php

<form action="fileTwo.php" method="post">
   <input type="submit" name="edit" value="edit" />
   <input type="submit" name="delete" value="delete" />
</form>

文件二.php

<?php
if (isset($_POST['edit']) && ($_POST['edit'] == 'edit')) {
    echo "Hello";
}
else if (isset($_POST['delete']) && ($_POST['delete'] == 'delete')) {
    echo "Goodbye";
}
?>

好的,这样你就不需要任何额外的代码,没有隐藏的输入,只有 2 个按钮。两者都将使用下一页上的处理程序正确处理它们所需的值提交您的表单。

于 2013-03-06T02:50:33.287 回答
0

制作两种形式:

< form action="execute.php" method = "POST">
< input type="hidden" name="delete" value="Remove"/>
< input type="submit" value="Delete"/>
< /form>

< form action="execute.php" method = "POST">
< input type="hidden" name="edit" value="Edit"/>
< input type="submit" value="Edit"/>
< /form>

在 fileTwo.php 中:

//input names(edit, delete) and values(Edit, Remove) are case sensetive
if( isset($_POST['edit']) && $_POST['edit'] == 'Edit') {
    echo"hello";
}

//if remove is clicked
if( isset($_POST['delete']) && $_POST['delete'] == 'Remove') {
    echo"good bye";
}
于 2013-03-06T01:10:17.473 回答