"Think you can handle my inner comedian and philosopher?"
Archives
Categories
Why Reinvent the Wheel for Web Forms?
We’re going to look at some business ideas that show why duplication is important. Then, we’ll use those concepts to introduce the FormVal Library, which uses PHP and Ajax to validate and submit web forms.
Feeling impatient? Skip straight to the code
Getting started - The likelihood of success in business
When I think about succeeding in business, two statistics come to mind:
- 95% of small businesses fail within the first five years
- Franchises like Subway are 95% (or higher) likely to succeed
Why? Because franchises like McDonald’s have a system of success that is passed on to each store. This includes the products, financial structure, how to run the store, everything.
Think about starting up your own business; doesn’t it sound like a headache? It takes a long time to get everything together, and an even longer time to succeed!
Moving on - Can franchising work for web development?
Code libraries are like franchises because everything is provided for you - you just have to do the work to integrate it into your website.
As a developer, you spend a lot of time learning the methods of design and code. Once you do have a good understanding of putting together a website, it makes so much sense to use libraries like Blueprint CSS, jQuery, etc.
The cool thing is, you can also modify existing libraries for your own purposes and pass them on further. Some libraries like jQuery allow you to develop additional modules so you don’t have to mess around with the base code.
FormVal Library - The Basics
In this case, the library is a collection of code. FormVal Library will help you build a successful web form, which includes structure, presentation, validation, and email generation.
The FormVal Library features:
- Valid XHTML 1.0 and CSS 2
- PHP and phpMailer
- Ajax with progressive enhancement
You can run this through the W3C Validator without error, so no worries about corrupting your code!
Special thanks to:
- Ralph DeStefano; Owner of Direct Response Web Solutions who taught me how to validate forms with PHP
- Jeremy Keith; He was awesome enough to write Bulletproof Ajax to help non-programmers use Ajax.
FormVal Library - What Resources are Included?
- form.php - The form features self-submitting validation and email with phpMailer. It also demonstrates how the session interacts with basic input fields, text areas, check boxes, radio buttons, and drop downs.
- validation.php - Runs regular expressions to validate the data in the form session.
- container.php - Includes the form and specifies the CSS and Javascript files. This demos the easiest way to include form.php in any given page.
- form.js - The Ajax functions are stored here and run when form.php is included in container.php.
- form.css - Sets the basic styles for container.php.
- /phpmailer/ - The form uses version 1.73 of phpMailer, an open source library from Sourceforge, which was released in 2005.
To be helpful, I’ve gone through the code and added some comments so you can follow along better. Your feedback in the comments area of this entry will be especially helpful in finding any bugs. Let me know what you think, too!