New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Validating form controls with Spry

From: Dreamweaver with PHP and MySQL

Video: Validating form controls with Spry

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.

Validating form controls with Spry

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.

Show transcript

This video is part of

Image for Dreamweaver with PHP and MySQL
Dreamweaver with PHP and MySQL

61 video lessons · 36127 viewers

David Gassner
Author

 
Expand all | Collapse all
  1. 8m 48s
    1. Welcome
      1m 25s
    2. What you should know before watching this course
      2m 17s
    3. Using the exercise files
      1m 40s
    4. Understanding the differences between Dreamweaver CS5.5 and CS6
      3m 26s
  2. 19m 31s
    1. Understanding static vs. dynamic web pages
      4m 32s
    2. Selecting application and database servers
      6m 10s
    3. Introducing Apache, MySQL, and PHP
      6m 36s
    4. Installing Apache, MySQL, and PHP
      2m 13s
  3. 39m 34s
    1. Defining a Dreamweaver site
      3m 22s
    2. Configuring a PHP testing server
      7m 48s
    3. Creating and testing a PHP-based web page
      8m 25s
    4. Adding PHP commands with the Insert panel
      3m 14s
    5. Setting and outputting simple variables
      3m 56s
    6. Testing pages with Live view and Live Code view
      2m 9s
    7. Using server-side includes
      7m 50s
    8. Navigating included pages with the Code Navigator
      2m 50s
  4. 36m 37s
    1. Using code hinting with PHP variables
      5m 31s
    2. Understanding PHP custom classes
      6m 38s
    3. Adding Zend Framework to PHP on Windows
      5m 18s
    4. Adding Zend Framework to PHP on Mac
      4m 2s
    5. Using the Site-Specific Code Hints feature
      3m 43s
    6. Using Zend Framework classes with code hints
      7m 26s
    7. Managing reusable code with the Snippets panel
      3m 59s
  5. 18m 27s
    1. Understanding relational databases
      5m 26s
    2. Creating a MySQL database in phpMyAdmin
      4m 41s
    3. Adding data in phpMyAdmin
      2m 46s
    4. Importing a completed database from a script
      5m 34s
  6. 39m 35s
    1. Defining a Dreamweaver database connection
      5m 27s
    2. Building a simple recordset
      4m 31s
    3. Building an advanced recordset
      5m 1s
    4. Displaying data with repeating regions
      6m 4s
    5. Displaying data in a dynamic table
      4m 15s
    6. Formatting dynamic data
      4m 54s
    7. Displaying the total number of records
      2m 4s
    8. Limiting records with paging controls
      4m 5s
    9. Creating conditional regions
      3m 14s
  7. 43m 12s
    1. Building a simple data entry form
      5m 27s
    2. Handling form submissions with PHP
      5m 12s
    3. Creating a customer email form
      3m 9s
    4. Validating form controls with Spry
      7m 54s
    5. Populating a list control with dynamic data
      4m 50s
    6. Working with multiple checkbox controls
      8m 5s
    7. Sending email with Zend_Mail
      8m 35s
  8. 50m 51s
    1. Using data wizards
      6m 20s
    2. Formatting dates for SQL
      5m 27s
    3. Creating a custom data entry form
      4m 50s
    4. Preparing a database table for server behaviors
      3m 3s
    5. Using the Insert Record server behavior
      5m 42s
    6. Preparing an update form
      7m 6s
    7. Using the Update Form behavior
      5m 46s
    8. Creating list page links to edit and update data
      7m 3s
    9. Using the Delete Record server behavior
      5m 34s
  9. 14m 45s
    1. Creating a login form with a PHP server behavior
      6m 29s
    2. Protecting page access with PHP server behaviors
      4m 17s
    3. Logging out with a PHP server behavior
      3m 59s
  10. 22m 50s
    1. Configuring a remote server with FTP credentials
      4m 42s
    2. Synchronizing site assets with the remote server
      5m 27s
    3. Exporting the MySQL database to a script
      3m 8s
    4. Importing the MySQL database on a remote server
      2m 24s
    5. Configuring the site for the remote database
      7m 9s
  11. 52s
    1. Final thoughts
      52s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.