php - 在帖子中丢失输入字段表单数据
问题描述
我有一个网站 (verlager.com),其表单调用 PHP 脚本“foo”。运行“foo”后;PHP 脚本加载配对模块。最大的问题是,在返回 index.php 时,费用数据从表单中消失了。
通常,我按住 Tab 键并取回大部分数据。除了问题是“费用”字段。那是字面意思。不是查找或计算。但我们需要它!
演示: http: //verlager.com点击文件夹图标加载播放器列表。按住 {tab} 填写玩家数据。双击费用栏输入字段。输入 25,这是我们的年度会员费。
点击“完成!” 配对列表在可移动的小框中加载了玩家的姓名。现在使用浏览器返回按钮返回上一页。表格的费用输入数据现在不见了!按住 {tab} 键会返回其他数据,但不会返回费用数据。
据我了解,有必要使用 PHP 会话来存储费用数据。PHP 脚本“foo”可以保存会话数据吗?
我应该改用 PHP 生成带有 player_name 和费用的 JSON 文件吗?我更喜欢(出于教育目的)使用 PHP 会话。
HTML
<div class="universal" ><div class="role">1.</div><div class="item ui-widget">
<input type = "text" id = "P1" onblur="calcEntryFee(this);" maxlength = "21" name = "N1" class = "autocomplete-2 text person" /></div>
<div class="item EF">
<input type = "text" onblur="findTotalEF();" name = "ef-fee" maxlength = "1" size = "1" id = "E1" /></div>
<input type="checkbox" onchange="findTotalEF();" class="item late pip" tabindex="-1" id="C1" />
<div class="item EXP"><input type = "text" onblur="getExpireDate();" class="CCCRexpDate" name = "cccr_exp" maxlength = "10" size = "10" id = "CCCR_X1" disabled /> </div>
<div class="item MEM" title = "double click to add mem. pmt." onclick="$('#M1').removeAttr('disabled')">
<input type = "text" onblur="calcEntryFee(this);findTotalMem();findTotalEF(); " name = "mem-fee" class="numbers fee fee_amt" maxlength = "2" size = "2" id = "M1" disabled /></div>
<div class="pure-u-1-12 RANK">
<input type = "text" onblur="getClass();" class="number" maxlength = "4" size = "4" id = "Y1" disabled /></div>
<div class="item USCF"><input type = "text" onblur="getUSCFexpireDate();" class="USCFexpDate" name = "uscf_exp" maxlength = "4" size = "5" id = "USCF_X1" disabled /></div>
</div>
PHP
<?php // "foo"
ini_set('display_errors', 1);
error_reporting(~0);
$myfile = fopen("players.txt", "w") or die("Unable to open file!");
$x = 0;
$max_entrants = 48;
for ($i = 1; $i <= $max_entrants; $i++) {
$tmp = "one, two"; $x = $i;
if (!empty($tmp)) {
$zed = trim($tmp," ");
if (strpos($zed, ', ') !== false) {
fwrite($myfile, $zed ."|");
}
}
}
fclose($myfile);
if (filesize("players.txt")) {header('Location: ../pairing.php');}
else {header('Location: ../index.php');}
解决方案
您可以下载一些软件包来实现此目的。它已被phpclasses.org组织的创新奖提名,提名评论是:
有时,应用程序的用户需要在表单中输入大量信息。
如果由于某种原因,例如电源或连接中断,他们没有在完成输入所有信息之前提交表格,他们可能会丢失之前完成的输入部分信息的工作。
此类提供了一种解决方案,可通过将草稿值保存到浏览器存储中以便以后恢复来防止用户丢失在表单字段中输入的值。
曼努埃尔·莱莫斯
你可以找到这个包PHP AutoSave Form Draft:将浏览器存储中的表单输入值保存为草稿。它是用 PHP 编写的,但使用 JavaScript 来实现这个目标......
推荐阅读
- amazon-web-services - 如何在我的模板中为 API 事件添加“/”?
- kubernetes - 是否可以为 kubernetes 主机网络 pod 选择内部 IP
- javascript - 将输入值与数组中的 JSON 对象匹配
- asp.net-core - 为什么 Giraffe/AspNetCore + SignalR 依赖注入无法解析 MailboxProcessor 单例?
- java - 如何在 Android 中切换主机
- ruby-on-rails - 无法在 Rspec 中发送带有标头的 put 请求
- ios - IOS/Objective-C:在没有 Storyboard Segue 的情况下可以在模态转换中使用自定义 Segue?
- android - 无法比较微调器选择的字符串值
- latex - 在背面将编译器更改为 XeLeTax 但仍然失败
- reporting-services - SSRS 多列报表分页不正确