• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 4. Using Forms with ColdFusion > Using Server-Side Form Validation

Using Server-Side Form Validation

The last thing that you want is for your site pages not to work properly. You need to make sure that a user has filled out all the required fields on a form before you try to process it. ColdFusion offers a built-in way to do this. By using server-side validation, ColdFusion can check to make sure that the user has filled in all the information in the form and that the information is properly formatted.

For this task, continue to work in the form you created in the previous task.

After the form field for the user name, enter this code:

<input type="hidden" name="name_required" value="You must enter your name"> 


By entering this hidden form field, you are letting ColdFusion know that the Name field is required and that the message “You must enter your name” should appear if the user tries to submit the form without it. You can specify any message you want in the value attribute. The message will actually appear in the form output page.


There are many different types of validation rules you can apply to your form fields. “_required” makes the field required. “_date” checks for the most common date formats. “_time” looks for the most common time formats. “_float” requires a number with decimals and “_integer” looks for non-decimal numbers. “_range” validates that the value is within a range of numbers.

Add the following two validation rules to your page:

<input type="hidden" name="email_required" value="You must enter your email"> 
<input type="hidden" name="comments_required" value="Please enter your
comment or question">


Now if a user submits the form with any empty fields, he would see an error message letting him know he has left out a required piece of information.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint