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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defining Session Variables

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

Question. Can you declare session variables before they actually have values?

I have a form that a user will fill out. I want some of the fields to become session variables, so do I define the session variables AFTER the form definition like follows:


<form>
...Form fields here
</form>
<cfset #session.variable1# = formfield value>
....
<cfset #session.variablen# = formfield value>



OR
Should I just have my form in FILEA.CFM and then when the user hits submit button, send my form data to FILEB.CFM and just declare the session variables there in FILEB.CFM?

I'm a little confused on when to declare session variables and when to apply values to them. Please advise.

Thanks in advance.
scripter73
 
Hey Scripter,

You can define session variables before you need to use them, but in the instance you showed the form variables don't exist until they have been submitted to a page. So in that case you would want to assign them a value in FileB.cfm

some people assign session variables in there APPLICATION.cfm file. This avoids some errors but can cause other problems. I tend to assign a value only when I have a value to assign, when you assign a value it defines the variable so you don't need to do anything else to define it before.

Hope that it clear.

Have fun...
 
Hi tlhawkins,

I sort of figured in my case it might be the Filea/Fileb case.

However, one more question.

Suppose FILEA.CFM is like this:

<form action=&quot;fileb.cfm&quot; method=&quot;post&quot; name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;field1&quot; value=&quot;ABC&quot;>
</form>

User hits submit, and the form data posts to FILEB.CFM.

Now I have FILEB.CFM and I want to access the fields.

How do I do that? I think I'm syntax-challenged. :)

I'm trying:

<cfoutput>Your field value is #form1.field1#</cfoutput>
and
<cfoutput>Your field value is #form.field1#</cfoutput>

I'm getting &quot;Error Resolving Parameter&quot;

Thanks for all of your help.

scripter73
 
My bad!!!

Actually to access the previous form's field values you can say, #form.fieldname.

My problem was that I was using a button called 'Continue' to redirect to FILEB.CFM, and I should have been using 'Submit' all along.

Sorry for any confusion.

Thanks again for all the great help!

scripter73
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top