简体   繁体   English

PHP的编辑按钮更好的形式或href链接?

[英]php edit button better as a form or href link?

I'm just curious what is the better method for edit buttons in an admin, keeping in mind the there could possible be 100s of these edit buttons on a page, 我只是想知道,在管理员中,有什么更好的方法来编辑按钮,请记住,页面上可能有数百个这些编辑按钮,

a form to use the POST variables 使用POST变量的表格

<form action="" method="POST" enctype="multipart/form-data" target="_self">
  <input type="hidden" name="ID" value="123" />
  <input type="hidden" name="name" value="ABC" />
  <button type="submit" name="action" value="Edit" class="edit></button>

or a href to use the GET variables 或href以使用GET变量

<a href="?action=Edit&ID=123&Name=ABC" class="edit">Edit</a>

I'm just curious in regards to speed and usability. 我只是对速度和可用性感到好奇。 Any opinions welcome. 欢迎任何意见。

Server Side 服务器端

Edit button or form button do not impact server side processing at all. 编辑按钮或表单按钮完全不影响服务器端处理。

If you are looking to reduce the html file size , the get variable based approach could help and reduce that less than 5% extra overhead (can vary based on type of application). 如果您希望减少html文件的大小,则基于get变量的方法可以帮助减少少于5%的额外开销(根据应用程序类型而有所不同)。

Client Side 客户端

The % impact on client side will also be negligible based on how browser handles the submit action. 根据浏览器处理提交操作的方式,对客户端的百分比影响也可以忽略不计。

Side Notes 旁注

  • href links work only as a replacement for GET forms and not for POST. href链接仅可替代GET表单,而不能替代POST。

  • url based approach is useful in cases like edit button where there is no user modified input 基于网址的方法在诸如“编辑”按钮等没有用户修改输入的情况下非常有用

Even better is using the HTTP PATCH method which meant to represent partial resource modification. 更好的是使用HTTP PATCH方法,该方法表示部分资源修改。

You should avoid using GET requests when the outcome alters a resource (because the request will be resent by hitting the back button). 当结果更改资源时,应避免使用GET请求(因为通过单击“后退”按钮将重新发送请求)。

However since many browsers cannot send native PATCH requests you need a bit of trickery. 但是,由于许多浏览器无法发送本机PATCH请求,因此您需要一些技巧。 Ruby On Rails for example uses javascript together with a method POST parameter to fake PATCH , PUT and DELETE requests - even on links. 例如,Ruby On Rails使用javascript和method POST参数一起伪造PATCHPUTDELETE请求-即使在链接上也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM