Electric Type

Multimedia

About Us

News

Help

Cool Forms with ColdFusion

Page 5 — How's Your Memory?

It really pisses me off when I have to retype information. It can happen for any number of reasons: I forget to fill out a field, I enter an incorrect address, the mouse slips - whatever. All I know is that when I hit a form, I will enter information a total of once. That's why memory is important.

Remember all of those <CFINPUT> tags you made a while back? It's time to revisit them. Go to your input.cfm file and, if you're using CF Studio, right-click on one of the input tags. Select the Edit Tag option. You should be back at the menu you used to add validation to the forms. If you haven't already done so, enter a name in the Name field. In the Value field, type in the name you just entered. Only this time, put pound signs (#) around the name. Repeat the process for every field in the form. If you're coding by hand, make sure you end up with something like this.

Of course, you remember that the pound signs make ColdFusion display the value of a variable. So by setting the value of the form element equal to itself, it will always remember what its last value was.

This simple step gives your forms memory. Now every time the form is sent back by the validation page, the information initially entered will reappear.

But just one cotton-pickin' minute. What about the first time? What happens if the form has never been submitted before? Without an existing value, the form will try to display something that doesn't exist. That's bad. We need to provide an initial value. To do this, we're going to go back to the application.cfm file and paste this into it:

<cfparam name="validation_error" default=""><cfparam name="choice" default="0"><cfparam name="name" default=""><cfparam name="address" default=""><cfparam name="city" default=""><cfparam name="state" default=""><cfparam name="phone" default=""><cfparam name="zip" default="">

By setting these parameters, you ensure that each form field always has something to display. And as you may have noticed, since the default value is blank the first time through, the form is entirely empty. It's a nice touch, don't you think?

This leaves the radio buttons. To give the radio buttons memory, here's what we're going to do - change the RB (that's short for radio button; you like?) to look like this:

<input type="radio" value="#id#" name="choice" <cfif choice eq id>checked</cfif>>

This checks the value of each radio button as it is being created. If it was checked before, the form will make sure it stays checked. But if it was not, it will be left blank. Again, since the default value is zero, the first time the form is displayed, none of the radio buttons will be checked.

Neat-o. Could it get any better? You bet.

next page»


Tutorials  

User Blogs  

Teaching Tools  

Authoring  

Design  

Programming help  

Advanced Flash  

Javascript  

Glossary  

PHP Coding  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.