【问题标题】:hidden field how to remove last part of url?隐藏字段如何删除网址的最后一部分?
【发布时间】:2015-10-18 21:24:25
【问题描述】:

我想从 url 中删除 GET 参数:

http://localhost/fadt/admin/edit_country.php?id=7

我希望我的网址变成:

http://localhost/fadt/admin/edit_country

这是当前生成链接的方式:

<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>

【问题讨论】:

  • 不知道我是否理解这个问题。您想从您输入的内容中删除它吗?
  • 我想删除 url 中的 id 值
  • 如果它不在您的 url 上,它不会被发送到您的服务器。如果您想将其发送到您的服务器但不显示在 url 上使用表单发送 post 请求,这将比在 url 上显示 id 但会隐藏 url 中的值造成更多麻烦。
  • 如果不包含变量(上面代码中的 7 ),那么脚本(edit_country.php)如何知道要编辑哪条记录??

标签: php apache .htaccess mod-rewrite


【解决方案1】:

使用带有 POST 方法的 HTML 表单代替按钮。

类似:

<form action="edit_country.php" method="post">
    <input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
    <input type="submit" class="btn btn-primary btn-xs fa fa-pencil" title="Edit"/>
</form>

代替

<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>

然后在edit_country.php 上使用$_POST 而不是$_GET

这个id 可以像您的按钮值一样容易地被操纵,因此请确保您正在验证执行用户是否有权执行操作。

更新,使用按钮:

<form method="post">
    <input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
    <button type="submit" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
</form>

【讨论】:

  • 工作,但我们可以替换任何其他按钮而不是提交
  • 你的意思是用button元素代替input,还是别的什么?
  • 是的...因为如果我使用提交按钮设计正在改变
  • 使用按钮类型提交&lt;button type="submit" class="btn btn-primary btn-xs" title="Edit"&gt;&lt;i class="fa fa-pencil"&gt;&lt;/i&gt;&lt;/button&gt;
  • IE 不同意你的观点并默认为按钮,我相信 webkit 也是如此,但我可能错了。在任何情况下,声明类型都不会有害
【解决方案2】:

不清楚问题,但我认为你需要这个

<?php

 $a =  explode('?','http://localhost/fadt/admin/edit_country.php?id=7');
echo rtrim($a[0], '.php')
 ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多