表单中的查询字符串不起作用

时间:2011-10-07 12:05:57

标签: php forms query-string

我在form.php文件中有以下表格:

<form action="operation.php?part=dictionary&operation=<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" method="get">
.....
....
</form>

在我的operation.php文件中:

if($_GET['operation']=='save'){
        echo "This is true";
    }else{
        die(mysql_error());
    }

它显示消息,它无法识别操作参数。 因此,如果有人知道如何区分保存和编辑之间的操作将非常感激。谢谢你

3 个答案:

答案 0 :(得分:1)

您可以尝试使用:

<form action="operation.php" method="get">
    <input type="hidden" name="part" value="dictionary">
    <input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>">
</form>

答案 1 :(得分:1)

您需要使用隐藏参数向表单提交值,如下所示:

<form action="operation.php" method="GET">
    <input type="hidden" name="part" value="dictionary" />
    <input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" />
</form>

答案 2 :(得分:1)

将表单的方法设置为“GET”会导致忽略添加到表单操作的所有GET参数。为了使这些参数起作用,您必须将它们添加为隐藏的输入字段,否则您将表单的方法切换为“POST”。这导致根据表单字段设置POST参数,并根据表单操作中的链接添加设置GET参数。