Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping form data

Status
Not open for further replies.

mtarby

Programmer
Feb 19, 2003
89
US
I'm trying to set up a form that will on submit, go into a SQL database.
What I'm trying to figure out is how allow a user to check a couple fields and hold the value of the field (like name and preceptor) - so when they submit the form and return to this page to enter the next patient information, that info will be populated until they uncheck the box.

(I'm envisioning something like an ecommerce option to make the shipping address the same as the billing address.)

Is it something I should be trying in javascript, or is a cookie more appropriate? Or is there a better way I'm not coming up with?

Thanks for any suggestions!

Michelle
 
At a very high level - to do something like this you'll need a way to identify your users. This will entail a registration form which will store their personal info in a database table. At that point you should write a non-expiring cookie so you can identify them on any given page and when they come back to the site after surfing. Here you'll have to check whether or not they have cookies enabled. If they don't you need to send them to a page that explains that they need to have cookies enabled to use the site. You'll also need to allow them to login if they decide to clean the cookies from their system. To keep it simple you probably could store all of their information in a cookie (depending on how much data we're talking about) and skip the database part but you need to be prepared to make them enter their info again if their cookie gets destroyed and you'll need to enforce cookies enabled.
 
i can't always guarantee users have cookies turned on, so one of the ways i do that is to pass the values back to the form page in a URL variable. i tend to do that on the server side tho...(we use coldfusion):

//do db insert...assume form values are validated

<cfset myformval1 = form.value_1>
<cfset myformval2 = form.value_2>

<cfquery name="dbinsert" datsource="my_db")
insert into mytable
(myformvar1, myformvar2)
values
('#myformval1#','#myformval2#')
</cfquery>

//now go back to the form page with values in url

<cfoutput>
<cflocation url="theformpage.cfm?submitted=1&val1=#myformval1#&val2=#myformval2#">
</cfoutput>

//theformpage.cfm contains the following:

<cfif isdefined("url.submitted")>

<cfset ret_val1 = url.val1>
<cfset ret_val2 = url.val2>

<cfoutput>
<input type="checkbox" name="value_1" value="#ret.val1#">
<input type="checkbox" name="value_2" value="#ret.val2#">
</cfoutput>

<cfelse>
<input type="checkbox" name="value_1" value="val1">
<input type="checkbox" name="value_2" value="val2">
</cfif>

do you follow?

there are other ways...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top