Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Understanding jQuery

jQuery is a library that brings a lot of functionality to JavaScript. Takes care of a lot of compatibility issues in different browsers but one of the most useful features is the way you can easily select elements. By far, selectors are the most powerful feature in JQuery. JQuery creates a global variable the dollar sign. To choose an element, you can pass a selector as a parameter of the dollar sign global. It works very much like CSS selctors. So, for example you can select our form like this.
Expand all | Collapse all
  1. 3m 36s
    1. Welcome
      1m 9s
    2. What you should know
      1m 2s
    3. Using the exercise files
      1m 25s
  2. 12m 50s
    1. Understanding forms
      2m 2s
    2. Working with form fields
      7m 4s
    3. Using the form tag
      3m 44s
  3. 19m 23s
    1. Using input validation
      2m 10s
    2. Adding required fields and placeholders
      1m 31s
    3. Constraining numeric and date fields
      2m 32s
    4. Accepting multiple entries
      1m 41s
    5. Limiting uploads by MIME types
      2m 35s
    6. Assisting text input with a datalist
      1m 55s
    7. Constraining with regular expression patterns
      6m 59s
  4. 42m 13s
    1. Accessing forms
      3m 57s
    2. Looking up form elements
      3m 35s
    3. Handling focus changes
      2m 47s
    4. Detecting the onchange event
      4m 31s
    5. Using the selectedIndex property
      2m 30s
    6. Dynamic validation with regular expressions
      7m 0s
    7. Creating a generic input validation function
      4m 31s
    8. Validating in older browsers with Modernizr
      7m 32s
    9. Interrupting form submission with onsubmit
      5m 50s
  5. 15m 20s
    1. Understanding jQuery
      3m 47s
    2. Validating on submit with jQuery
      3m 45s
    3. Building interactive jQuery validation
      2m 34s
    4. Using the jQuery Validation plugin
      5m 14s
  6. 32m 57s
    1. Communicating with PHP servers
      2m 27s
    2. Retrieving data from superglobals
      8m 18s
    3. Using server-side validation
      4m 59s
    4. Adding in-page validation
      5m 22s
    5. Mirroring input data back to the user
      7m 46s
    6. Sanitizing form input
      4m 5s
  7. 43m 29s
    1. Mailing form data
      8m 28s
    2. Understanding file uploads
      3m 1s
    3. Uploading files
      9m 20s
    4. Processing form data with AJAX
      8m 14s
    5. Preparing your database
      5m 50s
    6. Pushing data
      8m 36s
  8. 1m 17s
    1. Next steps
      1m 17s

please wait ...
Watch the Online Video Course Validating and Processing Forms with JavaScript and PHP
2h 51m Intermediate Apr 23, 2013

Viewers: in countries Watching now:

Validating web forms is a critical skill for any web developer, ensuring that the data that's submitted is complete, accurate, and nonmalicious before it's sent off to the server. Join author Ray Villalobos in this course as he shows how to validate input from site visitors with HTML5, JavaScript, and jQuery and then process the data with PHP. Plus, learn how to email form data and save it in a MySQL database so that it's ready for other applications.

Topics include:
  • Understanding forms
  • Adding required fields and placeholders
  • Accepting multiple entries
  • Limiting uploads
  • Handling focus changes
  • Validating with regular expressions
  • Working with older browsers
  • Building jQuery validation
  • Using server-side validation
  • Sanitizing form input
  • Uploading files
  • Sending form data to a database
Subjects:
Developer Web
Software:
JavaScript PHP
Author:
Ray Villalobos

Understanding jQuery

jQuery is a library that brings a lot of functionality to JavaScript. Takes care of a lot of compatibility issues in different browsers but one of the most useful features is the way you can easily select elements. By far, selectors are the most powerful feature in JQuery. JQuery creates a global variable the dollar sign. To choose an element, you can pass a selector as a parameter of the dollar sign global. It works very much like CSS selctors. So, for example you can select our form like this.

You can probably tell by the pound sign that we're asking jQuery to select an element with an ID of MyForm. If you want just the input fields belonging to our form, simply pass along the ID of the form plus a pseudo input selector. JQuery has a number of form specific pseudo selectors like input, checked, radio, submit and text. You can find all of them right here. In addition to that, you have the same type of events you are already familiar with in JavaScript. Events like blur, change, focus, submit, and value. You'll find those on this page.

The advantage of using jQuery events and selectors versus JavaScript, is they tend to be more powerful and consistent in behavior even in older browsers. So, I'm going to need to install jQuery in our form to do that I'm going to go to the home page of the jQuery website, and I'm going to click on this Download JQuery link. I'll scroll down to the part where it says "using jquery with a cdn." So I'm going to select just this one line. This other line supports legacy jQuery installations.

We're just using the current version, so this will be fine. So, I'm going to copy this, and I'll go into my code, and I'll put it right after the modernizer script. So, I'm going to save that, I'm going to go to the page for this code, and I'll refresh it and right click and select Inspect Element. Now from here, I want to go over to the console. Now to select a form element I just checked, the jQuery dollar global and I pass it along a string with whatever I want to choose. So if I want to choose my form, I'll just put # sign, MyForm and hit Return and that selects the entire form. If I want just the input fields in MyForm, I can add the pseudoclass selector input.

And if I hit Return, notice that it gives me all the form fields as an array. If you were to try to do that with JavaScript, you'd have to do something like this. Now, this is obviously a lot shorter but notice that the JQuery selector is choosing all the fields, including the Select and Text Area fields. That's certainly a lot more powerful. Choosing fields with specific attributes is also super easy. So, for example, if we want to get all the fields that have a required parameter, I can do that like this. That gives me an array of all the input fields with the parameter required. We could do the same thing for placeholders.

The difference is that choosing an element in this way will work in older version of IE consistently without needing modernizer. Let's say you wanted to get information about a specific field. Since our form fields have ID values, it's easy to select them. You can also choose an item's attribute with the type selector. Let's say we wanted to get pattern in the input field with the ID of my name. You can also get just the text of the pattern attribute or ATTR method.

Although I always think that it's good learn how to do things with regular JavaScript, jQuery does make it a lot easier to work with the DOM. Your code will also be more backwards compatible. If you want to learn more about jQuery and its selectors, make sure you watch jQuery Essential Training with Joe Marini.

There are currently no FAQs about Validating and Processing Forms with JavaScript and PHP.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Validating and Processing Forms with JavaScript and PHP.

Return to your organization's learning portal to continue training, or close this page.


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.