Classified Form Validation. I could not find a form validation script that suited my needs, so I concocted my own. I personally think it's quite robust and serves its purpose well. Here's the scheme I used tailored for my classified ad form:
- The Item field is required.
- Either the Email field or the Phone field must be entered -- you cannot leave both blank, but you can fill out both if you want.
- If you only fill out the Phone field, no validation occurs (you can specify this field to accept only numbers if you want more control). But if you fill out the Email field, the validation code kicks in for that field. Your email address will only be considered valid if it meets the following four conditions:
- It contains the "@" character.
- It contains a period.
- It has a minimum of six characters (since the shortest email address is theoretically email@example.com).
- It is one continuous string (i.e., no spaces).
It is relatively easy to add more rules to fit your particular needs. For instance, if you live in Canada and you only want to deal with customers living within Canada, you could add a condition which requires people to have ".ca" in their email address.
- The cursor is conveniently placed in the invalid field for you.
When you select the type of transaction, the Price field's default value is changed accordingly and the cursor is automatically placed in the Item field for you so you can just start typing.
You can try all this out for yourself by filling out the classified ad form below. To see the form in action, hop over to http://www.bayside.net/users/todo/ogo/panel.htm and click on the Market icon on the left bar, then select "Post." If you would like to find out how the scripts work, the simplest way is to dissect them and see how things tie together -- it's really quite simple. Of course a little experimenting doesn't hurt. If you are still a little confused, I will post an article on this subject in the "How To" section. Please let me know or nominate me if you find something useful here. Thanks!
Tom Doan <firstname.lastname@example.org>