Passing Data Between Pages
You've done a lot of reading and conceptualizing in this lesson, so now is a good time to roll up your sleeves and take a stab at a simple ColdFusion technique: passing data between pages. As discussed earlier, a key aspect of creating a meaningful user experience is customizing the experience by passing relevant data between pages and/or pages and the database.In this task, you'll create a simple Web form on one page and send that data to a second page. The second page will display the data entered on the first page. This exercise will show you how ColdFusion templates become simpl218 pages, and prove that you've configured your site correctly.In the newly defined Dreamweaver site, choose File > New to create a new page. In the General tab of the New Document dialog, under Category, choose Dynamic Page; under Dynamic Page select ColdFusion; and then click Create. When a new untitled document appears, call it test_output.cfm and save it in your local dante folder. With the page still open, choose File > Save As to create a second page called test_form.cfm .These two pages are throwaways that are not part of the application you'll be building. We often create throwaway pages for testing and prototyping purposes. We typically prefix the name with test_, so the test pages are grouped together alphabetically and we remember to delete them when we're finished experimenting.[View full size image]

1. | In the Dreamweaver toolbar, click the Show Design and Code views (Split view) button to display the document in a split window. |
One way to learn how to code in a language is to look at the code generated by programs as you work. Throughout these lessons, you should try to get a feel for ColdFusion. It's an easy markup language, and there's no substitute for having some ability with the code, even when you're working in visual environments like Dreamweaver.In fact, when you work in Dreamweaver, it's a good idea to do so in split view, especially if your monitor resolution is 1024 by 768 pixels or higher (with lower resolutions, it might get a little too crowded). If you've made it this far in the book, you should be comfortable enough to deal with the code behind the curtain.[View full size image]

2. | In the test_form.cfm page, insert the cursor after the opening <body> tag and press Enter/Return. Select the CFForms category of the Insert bar, and insert a CF Form Field. The cfform tag editor will open. On the General category, set the Action to test_output.cfm , the Method to post, and the name to bioData . |
[View full size image]


3. | Select the Miscellaneous category and set the Format to Flash. You can also choose a Skin at this time to style the look of your form. Click OK to close the tag editor. |
In ColdFusion you have the option of using standar217 forms or ColdFusion's cfforms. HTML forms are enclosed inside the <form> tags, and ColdFusion forms inside the <cfform> tags. We've chosen to use cfform to take advantage of the Flash format for a more attractive look to our form.[View full size image]

4. | Press Enter/Return to make space between your opening and closing <cfform> tags. With your cursor in the newly created space, insert a CF Text Field. The cfinput tag editor will open. In the General category, set the Type to text and the Name to firstName , and set Size to 20. Next, insert a new CF Text Field. Set the Type to submit and both the name and value to Submit . |
In this form, you ask the user for her or his first name, and then send the useras well as the data she or he enteredto the test_output.cfm page.Each value the user enters in a form will be stored in a variable with the same name as the form element. For this reason, you should always give your form elements meaningful names. Obviously, you're not likely to get confused by a variable in a one-element form, but you should develop good habits in anticipation of working with longer forms.[View full size image]

5. | Right-click the cfinput text named firstName and choose Edit Tag <cfinput> from the list of choices. Choose the Miscellaneous category and type Please enter your first name in the Label field. |
Functionally speaking, this step is completely unnecessary. None of these changes will affect what's sent in the POST. But the more minimalist you make your tests, the harder they'll be to understand later. It doesn't take much time to label text fields and make simple presentational changes, especially if they render the point of the page immediately obvious.[View full size image]

6. | Save and close test_form.cfm, and open test_output.cfm. |
You've completed the input page, and now it's time to build the output page, which will display the data that the input page just sent to it.Note that while we used cfform to create our form, the same thing could have been done with straightforwar217 form tags. In addition to richer design options, cfform provides other benefits, such as form validationbut that's beyond the scope of this exercise.
7. | Choose Window > Bindings to open the Bindings panel. |
The Bindings panel displays variables that you can use on the page. As you will learn, there are many kinds of sources for these variables, including URLs (thanks to GET), form variables sent via POST, and data brought in from a database via a query.Initially, a checklist appears, indicating the steps you'll need to follow to use data bindings. At this point you should have at least three of the five steps checked, which is sufficient to make use of a form variable sent via POST.

8. | Click the + button near the top of the Bindings panel, and choose Form Variable from the list. In the dialog that appears, type firstName . |


9. | In the main area of the document, enter the following text: Thank you, , for providing that information . |
Again, this is stati216. ColdFusion templates are often a combination of regula231 and ColdFusion markup.
10. | Place the cursor between the two commas, so it's snug against the second comma. In the Bindings panel, select firstName and click the Insert button. |


11. | Save the page. In the Files panel, hold down the Shift key and select both the test_form.cfm and the test_output.cfm files. Click the Put File(s) button to upload the files to the server. |
NoteIf the Include Dependent Files dialog appears, you can choose Yes or No, because there aren't any dependent files. Dreamweaver automatically displays this dialog so you can be sure to upload any images, Flash movies, and the like when you upload the page. Remember, you can't test the files by just opening them in your browser. They have to be processed on the server and then sent to the browser. You accomplish that by uploading them. And now for the moment of truth!

12. | Select test_form.cfm in the Site panel and press F12 (Windows) or Option+F12 (Macintosh) to test the file. |
Dreamweaver opens the file in your browser, using the URL prefix you specified earlier in this lesson. If you did it right, you should see the form.
13. | Enter a name in the field and click Submit. |
[View full size image]


14. | While still viewing the second page, choose View > Source (Internet Explorer), View > View Source (Safari), or View > Page Source (Firefox) to look at the code. |