Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Dreamweaver CS5 makes it very easy to add client-side validation to your data entry forms using validation controls that are part of the Spry framework. This isn't a new feature; Dreamweaver CS4 had it as well, but the number of available controls for validation has expanded in Dreamweaver CS5. I will show you how to add one of these controls and configure it. The data entry form that's already been created in the site has some validation tools but not everything we need. Let's take a look at the database structure that matches this data entry form.
I will go to the Databases panel, to the Explore California database connection, and then to the Tables list. Here is the table that matches the data entry form, and eventually we will receive data from it. The data entry form has controls that match the columns in this table. So there is a text field for the firstName and a matching firstName column, a text field for the lastName and a matching lastName column, and so on. Notice that many of these columns are marked in the database as required: the firstName, the lastName, the e-mail, and so on.
I am going to modify the form to make sure that the user enters values that are expected by the database. I won't do this for the entire form in this exercise. I will just do a couple of the controls. You'll have enough information to complete the task on your own. I am going to apply a required validation rule to these three controls, for the First Name, Last Name, and Email Address. I will start with the First Name. I will click on the Control, then I will go to the Insert panel, to the Spry category.
In Dreamweaver CS5, there are many validation tools available, including one for a TextField, for Textarea, Checkbox, Select, Password, Password Confirm and Radio Group. I'm going to apply the Spry Validation TextField. I'll click once, and that adds the code around the text field that's needed. Now let's take a look at the Spry text field properties. I will go to the Properties panel. You can leave the name of the text field alone.
I will match it to my control. I will call it spryfirstname. The Type list includes many different data types that you can look for. I don't need any particular data type here, so I'll leave that set to None. If you know how to use regular expressions - a way of creating string formats - you can choose Custom, and then you'll be able to enter a pattern. You can also add a minimum number of characters and a maximum number of characters. For example, in the database, the First Name text column allows up to 50 characters.
So I can match that in my Spry validation. When I select the maximum number of characters, the Preview states switches to something called Exceeded Max Number ofCharacters and at this point, I can change the error message that would display. I am going to switch the Preview state back to valid, and show you that there's a bit of text on the form already that we aren't going to need. I'll click into the Required element, and delete it, and I'll do the same thing for the versions next to Last Name and Email.
Then I'll go back to the Spry text field for spryfirstname, and I'm going to indicate when I want to validate. By default, validation happens on submit, meaning when the user clicks the button for the form. You can also cause validation to happen on Blur, which means when the user clicks or tabs out of the control, and on Change, which means when the user types. Validating on Change is overly aggressive for my money, so I will uncheck that option, and we'll only validate on Blur and on Submit.
Now I'll follow the same steps for the Last Name control. I will click the Control, go to the Insert panel and choose Spry Validation TextField. I'll click into the Properties panel, into the name of the control, and change it to sprylastname. I will once again set the maximum characters at 50, I will change the Preview state back to Valid, I will add the Validate on Blur, and once again, I am leaving Required checked.
Now, let's do the Email. I will click the Control. I'll add the Spry Validation TextField. This time, I'll set the Type to Email Address. Notice that the Preview state switches to Invalid Format. I am going to change that string by clicking into the preview state and changing that text to Expecting e-mail format. Then I will click back on the text field. I will add Validate on Blur, and the Maximum characters set to 50.
Finally, I'll change the name of the Spry TextField to Spryemail. So now I've added validation to these three controls: First Name, Last Name, and Email. I'll save my changes, and I'll be told by Dreamweaver that two new files are being added to my web site, named SpryValidationTextField.css and SpryValidationTextField.js. These files are used by Dreamweaver at runtime in the browser to cause the validation to happen.
When you deploy your site to your production server, you need to make sure that these files are included. I will click OK, and then I'll test the page in an external browser. I'll make sure that I am copying everything over to my testing server, and then I'll scroll down to the bottom and click the Join button, and show that the three validation errors are being displayed. I'll click into the First Name, and type "Joey," and the Last Name Smith, and notice that as I tab, the validation errors are being cleared.
That's because I added the Blur option for when I wanted to do the validation. Now, I'll type in an e-mail address, but I'll type it in incorrectly. I see the message, Expecting email format, and that's because I am missing the dot, and the characters at the end that exist in every e-mail address. So I'll click into the e-mail address again, and add the .com. I'll tab again, and now the field is valid. I'll also go down to my Password and Confirm Password elements and type some values in that will be valid.
And then, if I were actually submitting data to the server, I'd be ready to click the Join button. So that's a look at how to add some additional validation to your data entry form using Spry Validation components. The Spry Library is available for free from Adobe on opensource.adobe.com, but it's also included with Dreamweaver CS5, and you've seen how Dreamweaver CS5 generates most of the code you need for you. It's worth looking at the code that's generated by Dreamweaver to implement these features of the Spry Framework.
The Spry framework can be downloaded for free from Adobe's web site. Go to www.adobe.com/go/spry. This will take you to the latest version of the Spry framework. You can download this for free, take a look at the documentation, and use all of the elements of the Spry framework, even those elements that aren't automatically implemented by Dreamweaver CS5.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 75113 Viewers
80 Video lessons · 130017 Viewers
52 Video lessons · 64174 Viewers
59 Video lessons · 49973 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.