Form Data Validation / Server-Side Validation pt. 2
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Now this is just my sumaTemplate page and I have some notes in here so if you read through this on your own, which I think you may want to after this movie, you can see what's going on. So the first thing that's happening is we have a cfif statement using the IsDefined function to determine if a URL Variable exists or not. If it does not exist it's going to set it to none. What that is doing is making sure that there are no errors, so if I preview this in the browser again you can see I have no URL Variables; all that is doing is setting that URL.error to equal none. We're not really working with it quite yet. Now, down below, we have this information. What this is going to do is check and see if the URL Variable called Error is not equal to none. If it's not equal to none then we're going to populate this information and this is a cfoutput tag that is looping through a list and that is a list of all of the errors on our page, so it's simply displaying the errors with an asterisk in front of it and this is that red text that displayed the errors on my page. So these are all tags we've worked with so far. Now if I scroll down this is simply an HTML Form on the rest of the page, so this Validate Form validates to what action page, and that action page is listed up here in my form, validation action, so let's go over to that page and as you can see it's strictly code so nothing shows in the browser, so what this is doing is going through, testing for firstName through E-mail FormFields. I do not have any validation, as I said, yet for Radio buttons, Checkboxes and the Select Menu. What this is doing is checking to see if there's a value in the firstName field. If the length of the firstName field is zero, in other words, the user did not put anything in, it's going to set a URL Variable called error and make it equal to firstName. Then what we're doing is using a LIST function and we're creating a list of error variables we can use as URL Variables. If URL.error is none, in other words, if there were no errors, we're going to send them to the Thanks page. If there were errors, any type of errors, if this list has anything populated as far as errors, it's going to send them back to the form with an error URL Variable and that is going to list all of the errors that occurred right here. So, let's go back to the form, run that, so you can actually see those URL Variables again. So, I'm not going to plug anything in here. I'll click Contact SUMA and here they are. So, here are all of the errors in my error variable, so you can see this is a list-type of variable with commas in between and 7 form fields have a problem. This form field page is looking for an error variable. If it exists it's going to loop through the different errors and print out this information onto the page. So that is our Validation Action. Our location is going to send the user to the Thanks page with a URL Variable called Hello equal to Yes. So let's go over and look at Validation Thanks. What's going to happen here is ColdFusion is going to check and see if there's a URL Variable called Hello. If it's not defined it's going to send them back to the form. That prevents the user from getting to this page without having submit the form, so this is a three-page process. You may want to spend some time looking over the code in this so you fully understand it, but every concept within these lessons and these three pages have been put to work, so to speak, working together with ifs, elses, includes, location tags, loops, list type variables, et cetera. So, make sure you spend some time with these three pages so you fully understand what's happening with them. They all kind of work together to produce results for TextFields at this point.
Tutorial Information
| Course: | Adobe ColdFusion 8 |
| Author: | Candyce Mairs |
| SKU: | 34093 |
| ISBN: | 1-936334-05-4 |
| Release Date: | 2010-02-26 |
| Duration: | 8 hrs / 112 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 