|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS Flash Forms
Constructing an Application with Flash Forms from the Ground Up
You can do much more with them than with simple forms
Jun. 16, 2005 02:00 PM
Digg This!
Page 2 of 4
« previous page
next page »
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" 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 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" 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 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. Page 2 of 4 « previous page next page »
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||