• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Coldfusion newbie question insert question using sql2000

hi all

Newbie to CF, working on CF8 with a sql 2000 server.   Have my DB set and was wondering if what i want to do is possible.

it is a little inhouse crm type program, i have one page where user information is gathered.  

when the submit button is pushed it should check to see if certain values are selected from a drop down.  if they are selected then different sets of inputs are required .

eg. new customer --> ask what they want the pin and secret question to be
existing customer --> ask for account number and password

My question is , is there a way that when they fill out the first set of rules, it gets passed over to a second page but not written to the db until the second page of info is filled in. ?

sorry if its a trivial question but like i said i am newish to this.
0
PatrickMacC
Asked:
PatrickMacC
  • 8
  • 6
1 Solution
 
_agx_Commented:
Unless you have a ton of fields, it could all be done in one page w/javascript.  But if you prefer a 2 page approach that's certainly possible. Just store the values from page1 in hidden form fields on the second page. Then submit the whole thing to your final action page.  

There's ways to simplify it. But this is a good conceptual example

Page1.cfm
<h1>Page 1</h1>
<form action="page2.cfm" method="post">
	<input type="text" name="fieldA">
	<input type="text" name="fieldB">
	<input type="submit">
</form>

Open in new window



Page2.cfm
<!--- default for fields from page 1 --->
<cfparam name="form.fieldA" default="">
<cfparam name="form.fieldB" default="">

<h1>Page 2</h1>
<form action="finalActionPage.cfm" method="post">
	<input type="text" name="fieldC">
	<input type="text" name="fieldD">
	<!--- store page 1 values in hidden fields --->
	<cfoutput>
		<input type="hidden" name="fieldA" value="#form.fieldA#">
		<input type="hidden" name="fieldA" value="#form.fieldB#">
	</cfoutput>
	<input type="submit">
</form>

Open in new window


finalActionPage.cfm
<h1>finalActionPage.cfm</h1>

Display all form values
<cfdump var='#FORM#'>

Open in new window

0
 
PatrickMacCAuthor Commented:
Thanks, is there a way to store the info in a session var ? incase of a page crash ? or am i stupid for thinking such things ?
0
 
_agx_Commented:
Sure, you could use the session scope instead.  Assuming the fields in each page are uniquely named, any easy way to copy *all* fields is to use

       <cfset session.savedFields = duplicate(form)>

... or if you prefer you could set them individually

     <cfset session.fieldA = form.fieldA>
     <cfset session.fieldB = form.fieldB>

or am i stupid for thinking such things ?

No there are cases where you'd want to use the session scope. Just keep in mind it's limited too. If your session timeout is 20 minutes, and the user goes to lunch for an hour. The session will timeout while they're gone and obviously all the session variables are gone too.  

( If it's really critical stuff, you can capture the "end" of a session using an Application.cfc. I don't know that you need it, but let me know if that's something you're interested in ...)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
_agx_Commented:
Here's the same conceptual example using session variables instead.


Page1.cfm
<h1>Page 1</h1>
<form action="page2.cfm" method="post">
	<input type="text" name="fieldA">
	<input type="text" name="fieldB">
	<input type="submit">
</form>

Open in new window


Page2.cfm
<!--- save any fields from page 1 to session scope --->
<cfset session.page1Fields = duplicate(form)>

<h1>Page 2</h1>
<form action="finalActionPage.cfm" method="post">
	<input type="text" name="fieldC">
	<input type="text" name="fieldD">
	<input type="submit">
</form>

Open in new window


finalActionPage.cfm
<!--- save any fields from page 2 to session scope --->
<cfset session.page2Fields = duplicate(form)>

<h1>finalActionPage.cfm</h1>

Debugging: Display All Values
<cfdump var='#session#'>

Debugging: Show values individually
<cfoutput>
#session.page1fields.fieldA#<br>
#session.page1fields.fieldB#<br>
#session.page2fields.fieldC#<br>
#session.page2fields.fieldD#<br>
</cfoutput>

Open in new window

0
 
PatrickMacCAuthor Commented:
I have read a little about the power of the application.cfc , where would i upload that page to (the root ?) I would like to develop a log in system to the system and time out if someone is away from the computer.  

thansk for your help so far, im trying to learn as much as i can about CF 8 . I am waiting on a book from amazon to arrive , so its all internet research :)

0
 
_agx_Commented:
to the system and time out if someone is away from the computer.  

You'd probably want to use an Application.cfc with session variables (and maybe javascript too). But what do you want to happen when they "timeout"? Return to a login page, save their information to a db, etc... ?


where would i upload that page to (the root ?)

It all depends on what you the Application.cfc want it cover.  They apply to all files in the same directory and any subdirectories.  So if you place it in the root, it'll apply to all files in the root *and* any subdirectories.  

/Application.cfc  (ie "/" root)
/admin
/docs
/projects

Say you only wanted it to apply to CF files in your "admin" directory you'd place it in /admin/Application.cfc. Then it'd only apply to CF scripts in the "admin" directory (or it's subdirectories).
0
 
PatrickMacCAuthor Commented:
Thanks again, Learning a lot.

yes the goal would be just to time them out and loose the info, better to have no info in a db than missing data.

when it comes to the location of the application.cfc, if you have one in the root, can you put a different one in a sub and "override" the root one ?  (just a out of interest question).  I have to read up on what can be accomplished with the CFC file so i have a better understanding of it.

do you have anywhere on the web that shows a log in / out system using session vars on CF ?  if not i will play and figure it out :).. that how i learn most of the time :)...
0
 
_agx_Commented:
Well session variables timeout and drop all data automatically. You don't have to do anything special other than enabling session management.  ( To automatically return the user's browser to a login page after X minutes, that's more in the area javascript  ie client side not server side )

if you have one in the root, can you put a different one in a sub and "override" the root one ?

Yep. When you request a CF page, CF uses the 1st Application.cfc it finds (starting in the current directory).  If it can't find one in the current directory it walks the parent directories until it finds one.  So if you requested page:

           http://localhost/admin/foo/stuff/sub/somePage.cfm


/(root)
/admin/Application.cfc
/admin/foo/
/admin/foo/stuff/sub/
/admin/foo/stuff/sub/Application.cfc  <<===  CF will use this one

do you have anywhere on the web that shows a log in / out system using session vars on CF ?

There's a bunch of them. I can't think of a *good* one off hand. But let me look...

0
 
_agx_Commented:
You can test out what happens when a session ends.  Just create an Application.cfc with a very short timeout like 15 seconds.

Application.cfc
<cfcomponent output="false">
	<cfset this.name = "MyApp">
	<cfset this.sessionManagement = true>
	<!--- Set the timeout for 15 SECONDS: createTimeSpan(days, hours, minutes, seconds) --->
	<cfset this.sessionTimeout = createTimeSpan(0,0,0,15)>


</cfcomponent>

Open in new window


Create a test script (same directory) that sets a few session variables.  Run the page a few times w/in the timespan and you'll see some session variables.  Now wait 20 seconds. Notice all the session variables go away?

TestPage.cfm
<cfoutput>Time is: #now()#</cfoutput><hr>

Current session variables are:
<cfdump var="#session#">

<!--- set some variables so there's something to see ...--->
<cfset session.isLoggedIn = true>
<cfset session.firstName = "Bob">
<cfset session.lastName = "Smith">

Open in new window



0
 
PatrickMacCAuthor Commented:
hi, just tried to implement to the session passing mentioned above in my code, and here is what happened :)

sessions from first page went over to page 2 no problem

page 3 where the actual writing of the data takes place shows all of the vars for page2 session however it seems all the values from page 1 are missing :0

Error:
Element PAGE1FIELDS.FIRST_NAME is undefined in SESSION.

However Element PAGE1FIELDS.FIRST_NAME shows on the second page in a string no issue..

Any idea ? sorry :(
0
 
PatrickMacCAuthor Commented:
nevermind :) after i put in the application.cfc file things seemed to work :o  I am sorry
0
 
_agx_Commented:
after i put in the application.cfc file things seemed to work

Yep, you must use an application.cfc (or application.cfm for older apps) file to enable session variables.  This line in Application.cfc is what enables session variables:

    ie   <cfset this.sessionManagement = true>


the application.cfc file
BTW:  If you're using windows case doesn't matter, but on *nix systems the file name must start with an upper case "A"

    ie    Application.cfc


 
0
 
PatrickMacCAuthor Commented:
thanks again, and sorry for wasting your time on such a trivial matter .   but its nice to know that you are out there incase i have anymore basic questions :)
0
 
_agx_Commented:
You're welcome, and I don't think of it as trivial. When you're learning a new language, as good as the books and tutorials are, they never tell you everything. So it's nice to have others to bounce questions/ideas off of.  If you have any more questions, just ask :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now