Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Constructing an Application with Flash Forms from the Ground Up

You can do much more with them than with simple forms

It's important to note that the column name is key-sensitive and must match your database column name. The result of "contactList.selectedItem.columnName" will be the value of that specific column of the currently selected row, and that's exactly what we want to show in the input. By adding a binding to every input, we can magically populate them when the user selects a row in the contact list.

But that's not all we can do with bindings. We can use the binding syntax in other attributes besides the bind itself. For example, if we wanted to bind the label of a control with the data of another control, we would write:

label="{otherControl.text}"

We use that technique to change the value of the submit button to be in synch with the current operation. We show "Add new" when there's no item selected in the contact list, or "Apply changes" when an item is selected. The label of a button is given by its value attribute, so we write:

<cfinput type="submit" name="submit"
value="{(grid.selectedItem.id == undefined) ?
'Add new' : 'Apply changes' }" />

Because what goes between braces must be a single expression, we need to use the shorthand syntax for an if-else statement.

Step 4 - Validating Data
In almost every form we create, when we get input from the user, we must verify that the data entered meets minimum requirements. Sometimes we need certain fields to be mandatory, other times we must ensure that the data complies with specific formatting guidelines. From the user's standpoint, however, there's nothing more discouraging than getting an error message at the top of the form after the form has been submitted and comes back from the server and realize that the error was simply a missing zero in the month of a date field. Fortunately, we can avoid most of these user-unfriendly forms by using the built-in validation features in flash forms.

The most basic kind of validation is ensuring that required fields have been filled out. When we add the attribute required="true" to a <cfinput type="text"> tag, a red star is added to the input label and the form won't submit until that field is properly entered. The user will also get an alert indicating the error, and even better, a red border in the problematic field with an explanatory message will appear on the mouse over.

Let's take a look at the First Name field as an example:

<cfinput type="text" name="firstName" required="true" validate="noblanks"
message="First Name is required" />

Besides making the field required, we want to ensure that at least a non-blank character is entered, so we set the validate attribute to "noblanks." The message attribute lets us write a friendly message that will be shown in the red background when the user places the mouse over the field. If we don't specify it, a default message will show up.

Our form only requires the first name, last name, and e-mail. All other fields are optional, so we can simply omit the required attribute or set it to "false."

Once the data's been entered, we can validate it against one of the built-in types: date, integer, range, telephone, zipcode (US), e-mail, URL, creditcard, and others. You can take a look at the ColdFusion documentation for a complete list of types. What's nice about them is that the user gets notified with the red border and a message if the data doesn't validate as soon as he or she leaves the field, making it easier and faster to correct. See Figure 4.

Last, we may want to get the data in a specific format such as an ISBN number or an account number that must include dashes between the numbers. We can enforce such a pattern by using the mask attribute. For example, in the phone field, we use:

<cfinput type="text" name="phone" mask="999-999-9999" />

That means only three numbers followed by a dash, three numbers, a dash, and four numbers are allowed in that field. That may sound a little too much to ask from the user, but the good news is that the user will only need to enter the numbers (no other character will be written even if he or she hits the keyboard) and the dashes will be added automatically. If the user does add dashes, that will be fine too, because it will conform to the mask. Say goodbye to the three text inputs for phone numbers!

Step 5 - Showing Text and Pictures
Not everything in a form has to be an input of some kind. Sometimes we simply want to show a message or a picture. Because everything we want to have in the form has to be in the cfform tag and, unlike html forms, any text we put in between tags is ignored when we switch to flash format, we need a way to add text. That way is by using the cfformitem tag, a new tag added in ColdFusion 7. It lets us insert plain or html-formatted text and other elements such as rules or spacers.

We only want to show the contact information and a picture in the Preview panel. We'd also like the titles of the fields to be in bold. To be able to format the text like we want it, we need to use the html type of the cfformitem tag:

<cfformitem type="html">some html string</cfformitem>

If the text we want were simply a static string, we'd put it between the opening and closing tags. But in our case, we want to show the information specific to the selected contact in the contact list. How do we do that? Remember the bind attribute? Well, we can use the bind attribute to affect the value of the form item. Just like we bound the value of a text input to the selected item in the cfgrid, we can bind the value of the cfformitem to the fields in the Edit panel. We are, in fact, chaining the binding in such a way that when the selected item in the contact list changes, the text inputs get populated with the data, and that in turn populates our html cfformitem. It may sound more confusing that it actually is, so let's review the code for the picture.

More Stories By Nahuel Foronda

Nahuel Foronda is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where he has been creating award-winning applications and offering training for the last five years. He also maintains a blog, called AS Fusion (http://www.asfusion.com), where he writes about Flash, ColdFusion and other web technologies.

More Stories By Laura Arguello

Laura Arguello is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where she has been creating award-winning applications and offering training for the last five years. She also maintains a blog, called AS Fusion (http://www.asfusion.com), where she writes about Flash, ColdFusion and other web technologies.

Comments (11) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
RockDad 11/06/08 01:39:48 PM EST

How would one modify this app to only allow employees to edit their own information assuming there is a cookie identifier already setup?

RockDad 11/03/08 02:08:32 PM EST

GREAT tutorial but how does one bind a cfselect object with the grid? Tried it and it doesn't work. Any ideas?

Mike 01/23/08 12:19:45 PM EST

where can I get the source code for this article - "Constructing an Application with Flash Forms from the Ground Up"

wholesale ipod 10/30/07 01:18:03 AM EDT

I think so!

Garfield 07/24/05 07:47:15 PM EDT

Great article by great developers. I have just starting using CF7 and thanks to many writers out there, I have developed some impressive forms. Please visit the www.asfusion.com site for more helpful info.

Michael, visit http://www.cfform.com/flashforms/invoke.cfm?objectid=0204C17F-4E22-1671-... for a tutorial on binding grids to selects. Be mindful that when binding to a grid, the bind is both case and type sensitive to the DB columns.

Michael White 07/17/05 07:39:37 PM EDT

Your article was a good introduction to flash forms with multiple panels. I have a question on the Edit panel... what if some of your fields are CFSELECT dropdowns or date fields... having trouble finding working syntax for binding them to the grid.

Andrew 07/06/05 11:40:46 PM EDT

Loved the article! It has taught me alot. Maybe I am at fault here but I am not able to get any of this to save or edit in a db anyone else having same problem

Laura Arguello 06/27/05 08:30:39 PM EDT

Thank you for the comments.
While the link gets fixed, you can download the source code from http://www.asfusion.com/blog/files/cfforms/cfdj_source.zip

Anthony 06/25/05 05:40:50 PM EDT

How do I download the source files for this article?

[email protected]

Stiles 06/25/05 11:53:31 AM EDT

I'm having a similar problem with getting the source code for this article. The printed version states that the source code can be downloaded at www.cfdj.com. This URL is invalid and not a site maintained by Sys-Con. Any chance the link can be updated so we can view the source code?

Much appreciative.

André 06/24/05 09:48:25 AM EDT

Hi,

Thank you for the article, I found it very informative, well written and helpfull. I am having difficulties with the save content section. How could one download the source code ?Could it be possible to modify the link to open on the file rather to to another site that does not seem to be CF Dev. Journal ?

Again that you for sharing.

IoT & Smart Cities Stories
Early Bird Registration Discount Expires on August 31, 2018 Conference Registration Link ▸ HERE. Pick from all 200 sessions in all 10 tracks, plus 22 Keynotes & General Sessions! Lunch is served two days. EXPIRES AUGUST 31, 2018. Ticket prices: ($1,295-Aug 31) ($1,495-Oct 31) ($1,995-Nov 12) ($2,500-Walk-in)
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...