bigfork/silverstripe-form-idempotency
Composer 安装命令:
composer require bigfork/silverstripe-form-idempotency
包简介
Idempotency key support to help prevent duplicate form submissions
README 文档
README
Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. Wikipedia
This module is designed to help prevent duplicate form submissions, particularly when users click a submit button repeatedly in a short period. For standard HTML forms this will result in the browser “cancelling” previous POST request(s) and submitting new ones, however if the server has already begun processing the request then this comes too late to prevent the POST submissions being handled multiple times.
Note that this is not a replacement for spam protection, in fact this is designed specifically for forms without spam protection as many spam protectors will already ensure a form can only be submitted once.
Overview
- When a form is rendered, a unique “idempotency key” is generated and stored in a hidden field
- On submission, the server will check the user’s session to see if this key has already been submitted
- If the key hasn’t been seen before (i.e. the first submit), the form handler is called as usual
- The result of the form action is then serialized and stored in the session
- If the form is submitted again with the same idempotency key, the form handler is skipped and the serialized result from the session is returned
Installation
composer require bigfork/silverstripe-form-idempotency
Usage
Call $form->enableIdempotency() when constructing your form.
Limitations
- The result returned from the form handler (your “
public function doSomething()”) is stored in the session, so it must be serializable. A typical response (e.g. a redirectHTTPResponse, or anHTMLTextinstance like a rendered template) is already serializable, but if you’re doing anything heavily custom you may need to check. - If your form handler redirects, there’s a narrow window between (1) when the client receives the redirect response & the browser issues a GET request to the destination, and (2) when the client receives the response from the GET request to the destination. If the user clicks submit again within this window, session messages (such as form or “flash” messages) may be lost, as the GET request will cause them to be rendered and cleared. This is rare, and the cached response described above will still be returned, but if you rely on one-time session messages being displayed as feedback then it’s possible these may not always appear.
bigfork/silverstripe-form-idempotency 适用场景与选型建议
bigfork/silverstripe-form-idempotency 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bigfork/silverstripe-form-idempotency 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bigfork/silverstripe-form-idempotency 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 487
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-09-20