Author Topic: HTML form validation  (Read 1776 times)

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
HTML form validation
« on: January 12, 2012, 10:51:00 PM »
I have a huge form (more than 100 questions), mostly radio button selections and a few text fields. I want to make sure every question is answered before the form can be submitted. Is there a way to iterate over the form elements to do this? Instead of manually writing out a check for each one? If I iterate over the form DOM, how do I know what type of form element it is? (Since radio buttons will be validated differently from text fields).

Ideas?

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: HTML form validation
« Reply #1 on: January 12, 2012, 11:01:55 PM »
First, remember the most important rule:  Client side validation is for the client not for security.  Remember that users are the enemy.

For client side I would just look at a jquery form validator.

Some things to remember:
you can look at the type attribute for the tag to determine what type of input it is.
radios work best with a default value
unchecked check boxes don't set a value in the post