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)

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.


IoT & Smart Cities Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
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...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
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...