$_POST[ "action" ] == "edit"

  • 本文关键字:edit action POST php
  • 更新时间 :
  • 英文 :


如何转到此if (isset($_POST["action"]) && $_POST["action"] == "edit") statement

if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["action"]) && $_POST["action"] == "edit")    {
//Assemble the the postData
);
//Call the RestClient with PUT
RestClient::call("PUT",$postData);
}
}

当我像这样点击'edit'按钮时?

<h4>Edit Customer - <?php echo $c->getCustomerID(); ?></h4>
<!-- The above form looks like this -->
<form method="POST" ACTION="<?php echo $_SERVER["PHP_SELF"]; ?>">
<!-- Would some hidden fields help to route the data?  Probably -->
<div class="row">
<div class="six columns">
<label for="name">name</label>
<input type="text" name="ename" value=<?php echo $c->getName();?>>
</div>
<div class="six columns">
<label for="name">address</label>
<input type="text" name="eaddress" value=<?php echo $c->getAddress();?>>
</div>
<div class="six columns">
<label for="name">City</label>
<input type="text" name="ecity" value=<?php echo $c->getCity();?>>
</div>
</div>
<input class="button-primary" type="submit" value="Edit">
</form>

如果你想获取提交按钮的值,你必须做的第一件事就是给它一个值为"action"的名称:

<input class="button-primary" name="action" type="submit" value="Edit">

然后与按钮的值完全匹配(意思是区分大小写(:

if (isset($_POST["action"]) && $_POST["action"] === "Edit")

这就是你应该做的,尽管这是没有意义的,除非你要有多个表单,每个提交按钮的名称都是"action",而这样做不是一个好的做法一个更明智的方法就是给提交一个反映操作的名称:

<input class="button-primary" name="edit" type="submit" value="Edit">

然后简单地检查是否设置了该名称:

if (isset($_POST["edit"]))

还要注意,ACTION="<?php echo $_SERVER["PHP_SELF"]; ?>"是不必要的,因为默认操作是提交给self,所以您可以删除整个属性。

您只需要添加一个隐藏的输入

<input type="hidden" name="action" value="edit"/>

相关内容

最新更新