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!

PASSING VARIABLES BETWEEN PAGES 1

Status
Not open for further replies.

alexfusion

Programmer
Feb 5, 2001
94
AR
Hello Everyone:
Simple question here:
How do I pass CF variables from one page to another.I am not referring to a value entered in form.
For instance:
<CF SET VARIABLE1=&quot;FIRST NAME&quot;>
This is the variable in the first page.
How do I pass the value of the variable to a second page to process it?

Thanks in advance

alexfusion


 
There are of course a number of ways to do this.
The method you should choose is dependant of what kind of an application you are trying to build.

What you need to do is to read the CF documentation (no, its not that much), and I sugest that you start with:

application variables (carefull with these)
session variables
and client variables

you could also try passing them by URL, something like this:
<cfoutput>
<A HREF=&quot;page2.cfm?varnam=#VARIABLE1#&quot;>your link</A>
</cfoutput>

Or maybee in a hidden form which you submit with
some javascript.
 
Thank you lennartr for your advice and help.They are priceless to me.

Kind Regards

alexfusion
 
If you want to pass variables in the short term, using session variables are the best.

in your application enable session variables with something like

<cfapplication name=&quot;whatevername&quot; sessionmanagement=&quot;Yes&quot;>

then do you can do a example below of querying a database to get and set session variables. You will need to read up on <cflock> to make you don't crash your cfserver when using session variables.

<!--- Find record with this Username/Password --->
<!--- If no rows returned, password not valid --->
<CFQUERY NAME=&quot;GetUser&quot; DATASOURCE=&quot;#DataSource#&quot;>
SELECT NickName, CompanyName
FROM Customers
WHERE NickName = '#Form.UserLogin#'
AND Password = '#Form.UserPassword#'
</CFQUERY>

<!--- If the username and password are correct --->
<CFIF GetUser.RecordCount EQ 1>
<!--- Remember user's logged-in status, plus --->
<!--- ContactID and First Name, in structure --->
<CFSET SESSION.Auth = StructNew()>
<CFSET SESSION.Auth.IsLoggedIn = &quot;Yes&quot;>
<CFSET SESSION.Auth.NickName = GetUser.NickName>
<CFSET SESSION.Auth.CompanyName = GetUser.CompanyName>

<!--- Now that user is logged in, send them --->
<!--- to whatever page makes sense to start --->
<CFLOCATION URL=&quot;#CGI.SCRIPT_NAME#&quot;>
<CFELSEIF GetUser.RecordCount EQ 0>
<tr><td colspan=&quot;2&quot; align=&quot;center&quot; class=&quot;stfont2&quot;>Incorrect Account Number or Password.</td></tr>
</CFIF>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top