Fusebox 4.1 For Beginners Part 2
Untitled Document

Fusebox 4.1 For Beginners Part 2

Fuseactions

Now that you have a circuit and an action for that circuit you will want to create the page that will be that action. If you just said "huh?" don't worry it will become clear in a moment. Open up your favorite editor and create a page called dsp_welcome.cfm. In that page I would like you to type the phrase "Hello, I am an action called "welcome"." Save it to the same folder as your index.cfm file is in. Once that is done open up index.cfm in your browser again. Go ahead I'll wait for you.

If you are cursing up a storm because you received a error message that read something like this, "The circuit xml file, circuit.xml, for circuit Main could not be found" you have done everything correct so far and can stop cursing. So what happened? Well the short of it is that we have set up a circuit called main and an action of welcome that is our default fuseaction, but we haven't specified what the action should do. So we want to specify that our action is to open up the dsp_welcome.cfm page. We do this by opening the circuit.xml.cfm document and placing the following text there between the fuseaction tags we added:

<include template="dsp_welcome.cfm" />

Your file should now look like this:

Circuit.xml.cfm
<circuit access="public">
    <fuseaction name="Welcome">
       <include template="dsp_welcome.cfm" />
    </fuseaction>

</circuit>

Ok once you have that done save and open up index.cfm in your browser again. Go ahead I promise it will work correctly now. If you have done everything exactly as I have it you should see that the dsp_welcome.cfm is showing. But how is this possible? Everything goes through the index.cfm page. This provides for better security along with easier control. And since main.welcome is your default fuseaction you will always see this page if you type in index.cfm. Go ahead and try to open dsp_welcome.cfm in your browser see what happens. It automatically calls back up the index.cfm page. So how is this possible. Open the application.cfm page.

In it you will see this:

<cfif right(cgi.script_name, Len("index.cfm")) NEQ "index.cfm" AND right(cgi.script_name, 3) NEQ "cfc">
    <cflocation url="index.cfm" addtoken="no">
</cfif>

This keeps any page, but the index.cfm page from being opened providing security for your scripts, because now a user will no long see the name of the page being called! What a great idea!

Ok now that we have a basic hello page lets beef it up. Open up dsp_welcome.cfm we want to make it go to another page call dsp_yourname.cfm, but we want it to actually say a persons name. So we will insert a form. On the dsp_welcome.cfm page type the following:

<form action="index.cfm?fuseaction=main.DisplayName" method="post">
    <input type="text" name="name">
    <input type="Submit" value="submit">
</form>

So your dsp_welcome.cfm page should look like this:

dsp_welcome.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form action="index.cfm?fuseaction=DisplayName" method="post">
    <input type="text" name="name">
    <input type="Submit" value="submit">
</form>
</body>
</html>

Now look at the form action. We call the index.cfm page and we pass a variable called fuseaction with a value of DisplayName. So how do we call the dsp_yourname.cfm page we are about to make? If you said by placing some script in the circuit.xml.cfm page you are correct and probably should not be reading this tutorial. ;-) Really we want to open the circuit.xml.cfm page and place the following code there:

<fuseaction name="DisplayName">
   <include template="dsp_yourname.cfm" />
</fuseaction>

So now your circuit.xml.cfm looks like this:

Circuit.xml.cfm
<circuit access="public">
    <fuseaction name="Welcome">
        <include template="dsp_welcome.cfm" />
    </fuseaction>
    <fuseaction name="DisplayName">
        <include template="dsp_yourname.cfm" />
    </fuseaction>
</circuit>

Ok now create a new page and name it dsp_yourname.cfm. In it put the following code:

<cfoutput>Hello my name is: #Form.Name#.</cfoutput>

Now open index.cfm in your browser. You should see the newly created form. Type in your name and click submit you should now see your name and the hello message. If so great! You have done everything correct so far. If not go back over your code and match it exactly to mine.

Now it is time to get a little more advanced with this and start experiencing the power behind fusebox. So go to the potty, get yourself your favorite drink, and buckle your seat belts then move on to part three of this series.

 



All ColdFusion Tutorials By Author: Craig
  • Actionscript Basics in CFFORM
    This tutorial teaches some basic ways to achieve effects using actionscript with your flash forms.
    Author: Craig
    Views: 10,136
    Posted Date: Tuesday, February 27, 2007
  • CFCs in Fusebox
    This final part in the tutorials about fusebox 4.1 will explore the use of CFCs.
    Author: Craig
    Views: 7,007
    Posted Date: Tuesday, April 25, 2006
  • Creating a chat system with Flex and Coldfusion
    This tutorial will cover both the Flex and Coldfusion areas of a chat application that uses the users computer to store the entire chat log and coldfusion only stores the 5 newest messages.
    Author: Craig
    Views: 3,212
    Posted Date: Wednesday, February 6, 2008
  • Fusebox 4.1 For Beginners Part 1
    This four part series will introduce cf beginners to the fusebox frame work and help them get a grasp of this powerful technology.
    Author: Craig
    Views: 15,868
    Posted Date: Monday, July 4, 2005
  • Fusebox 4.1 For Beginners Part 2
    This four part series will introduce cf beginners to the fusebox frame work and help them get a grasp of this powerful technology.
    Author: Craig
    Views: 18,015
    Posted Date: Monday, July 4, 2005
  • Fusebox 4.1 For Beginners Part 3
    This four part series will introduce cf beginners to the fusebox frame work and help them get a grasp of this powerful technology.
    Author: Craig
    Views: 11,999
    Posted Date: Monday, July 4, 2005
  • Fusebox 4.1 For Beginners Part 4
    This four part series will introduce cf beginners to the fusebox frame work and help them get a grasp of this powerful technology.
    Author: Craig
    Views: 11,673
    Posted Date: Monday, July 4, 2005
  • Turning up the heat in Fusebox 4.1
    This tutorial teaches you some methodology and new xml tags you can use to create complex, but easy to use application in the fusebox framework.
    Author: Craig
    Views: 6,741
    Posted Date: Thursday, October 27, 2005
  • Using Flash Remoting to take your CFForms Farther
    This tutorial shows you how to make a remote connection to a cfc using actionscript for your cfforms.
    Author: Craig
    Views: 8,838
    Posted Date: Saturday, July 22, 2006