输入后丢失输入字段表单数据

时间:2018-08-03 16:21:33

标签: php

我有一个网站(verlager.com),其形式调用PHP脚本“ foo”。运行“ foo”之后; PHP脚本会加载配对模块。 问题是,返回index.php时,费用数据已从表格中删除。

通常,我按住Tab键并取回大部分数据。唯一的问题是“费用”字段。那是字面上的。不是查找或计算。但是我们需要它!

演示:http://verlager.com单击文件夹图标以加载播放器列表。按住{tab}以填写玩家的数据。双击费用列输入字段。输入25,这是我们的年度会员费。

点击“完成!”配对列表在小小的可移动框内加载了玩家的名字。现在,使用浏览器后退按钮返回上一页。表格的费用输入数据现在消失了!按住{tab}键将带回其他数据,但不会带回费用数据。

据我了解,有必要使用PHP会话来存储费用数据。 PHP脚本“ foo”可以保存会话数据吗?

我应该改为使用PHP生成具有player_name和fee的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');}

1 个答案:

答案 0 :(得分:0)

有一些软件包可以下载以实现此目的。它是phpclasses.org组织的创新奖的提名者,提名的评论是:

  

有时应用程序的用户需要输入很多信息   形式。

     

如果出于某种原因(例如电源或连接性)   中断,他们在完成输入之前不提交表单   所有信息,他们可能会丢失之前输入的工作   部分信息。

     

此类为防止用户失去价值提供了解决方案   通过将草稿值保存到浏览器存储中在表单字段中输入   以后可以恢复。

     

Manuel Lemos

您可以找到此软件包PHP AutoSave Form Draft: Save form input values in browser storage as draft 。该软件包是用PHP编写的,但使用JavaScript可以实现此目标...

相关问题