;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM 
您的位置 :首页 >> CF 技巧文章 >> 阅读文章内容 [ 关闭窗口 ]      

技巧文章内容 
    如何在用户刷新页面时候不丢失用户输入的资料呢? (英文)
文章作者 : linkfoxo [ webmaster@cfwindow.com ]          Web URL : http://www.cfwindow.com
上载日期 : 2000-12-18

如何在用户刷新页面时候不丢失用户输入的资料呢?

The Situation: You have created a form that you want to let the user return to -- but with the information they entered still in the form fields. Right now, it comes back blank.

The Solution: You will need to use persistent variables. While normal variables go away when your browser changes pages (hence the problem!), persistent variables stick around and can be accessed. At present, ColdFusion 4.x supports cookies, client, server, session, and application variables.

Which you use depends on a number of things. Do you need to store this information for only a few hours? Does it need to be for longer? Once you've decided on the type of persistent variable you want, you'll need to rework your form page. Here I'm using session variables.

<cfparam name="session.firstName" default="">
<cfparam name="session.lastName" default="">
<cfparam name="session.city" default="">

<form action = "doMyForm.cfm" method="post">
First name: <input type ="text" name = "firstname" value="#session.firstname#">
<br>
Last name: <input type ="text" name = "firstname" value="#session.lastname#">
<br>
City: <input type ="text" name = "firstname" value="#session.city#">
<br>
</form>

Next, your form processing page needs to save all the form variables into the kind of persistent variables you've chosen. Something like...


<cfsetting enablecfoutputonly = "yes">
<cfif isdefined("form.fieldnames")>
  <cfloop list="#form.fieldnames#" index="field">
  <cfset setvariable("session.#field#","#evaluate("form."&"#field#")#")>
  </cfloop>
</cfif>
<cfsetting enablecfoutputonly = "no">

Now, whenever your user goes back to the form page, the form will populate itself with the values contained in your persistent variables. The <cfparam> tags on the form page ensure that if this is the user's first time at the form, s/he will see a blank page ready for them to enter their info.








< 联系我们 --- 中国Cold Fusion用户组>

CFUG 国内(总部):Linkfoxo    上海:CFANS    北京:Cafe,Cyberkid,liwater    沈阳:Wangking
  
哈尔滨:Baiming    浙江:梅盛松    江西:陈末
  
CFUG (国际) Nagoya(名古屋):Codeguru    新加坡:YUZI    新西兰(Auckland):Richard CHEN
Copyright 2000-2001 www.cfwindow.com.All rights reserved

;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM