= Quickstart 5: Validating a Form = Our translation form doesn't require the user to enter a value. Our application doesn't fail, but it'd be nice to server-side validate the form. (Actually, it's not just nice, it's something you should do for every form, every time.) Using the translateForm function, it's easy to check if the form as been filled out. However, how do we alert the user? How do we take them back to the form, instead of showing the result? The tag has a third child tag, , that's custom made for things like this. Adding a and tag to our translationFormAction event handler, we end up with the following xml: {{{ }}} What does that tag mean? It means that if I somehow state that the event has a validation error, immediately stop processing the event and redirect to the translationForm event. So how do we indicate that there's a validation error? We test a condition in our controller, and if necessary, add the result to arguments.event: Doing this, the !TranslatePhrase function now reads: {{{ }}} Try the submitting the form without filling in a phrase. You'll wind up right back at the form. That's OK, but we need to provide an error message. Remember, we can use controller functions to add values to the viewstate that view templates can display. Let's first add an error message to !TranslatePhrase: {{{ }}} Then, change frmPhrase.cfm to display the phrase error, if one has been set: {{{

#event.getValue("phraseError")#

}}} ---- Back [wiki:QuickStart/4:HandlingaForm#Quickstart4:HandlingaForm Quickstart 4: Handling a Form] Next [wiki:QuickStart/6:AddingaSiteWideTemplate#Quickstart6:AddingaSite-WideTemplate Quickstart 6: Adding a Site-Wide Template]