Main Content

Short and sweet and sticky - PHP form input

Archive - Originally posted on "The Horse's Mouth" - 2008-02-06 23:13:02 - Graham Ellis

Today I have a short and (very) sweet PHP demo that calls for a user to enter a few pieces of information, and validates them - prior to storage in a database, perhaps.

Why is it "sweet"?

* Because it implements techniques such as sticky fields so that user who make error don't have to keep re-entering

* Because it validates user inputs and gives good error messages

* Because it handles awkward characters, injection attack attempts, etc

* Because it can be shifted from one URL to another without any code changes

* Because it can be easily modified to include any number of extra fields with their validation without having to do lots of low level code

* Because it can be very easily split into three elements - standard functions, a template for the HTML, and the applications top level making it a good foundation for the "4 layer model" approach

Try it out here

See the source here

When you're writing PHP look at each of those "because" clauses and aim to write your code to meet as many of them as possible. Good for the author, good for the user, good for the maintainer.