Abstract Form Handling

I've already gone over some basic form handling and form best practices with my last few posts, but building with an object-orientated MVC starts to throw forms into a different light. It's very easy to abstract out forms with their repetitive logic patterns, something that I've recently done on one of my side projects. While I don't want to explain the code line-by-line, this post will go over some of the basic thought processes and steps I took to make my abstracted form handler.

Form Wrapper

The first logic I worked out was the definition of a form. To create each new form, I create a new class that is abstracting off a base pattern. Each form class defines form elements within a standard 'get' method. This way I can call on individual form elements easily or call the entire class to pull the whole form. Example...

read more »

How Many Tiers for a Clean View Layer?

An interesting possibility cropped up for my MVC a few weeks ago. I've been working with microformats on and off the last few months (you can read about one of my first adventures with them when I created a microformatted resume). I started to wonder where else my site could use this new feature. An easy place to add microformat tags are links - you can add a 'rel' attribute that describes the relationship of the link to your site. Also, if I added a layer of abstraction to my links site wide, then I could easy add behavior rules (target="_blank" and whatnot) that would affect an individual link across all of my pages and sites.

This idea would involve creating a table of all my links, internal and external, that could be mapped to meta information about the links. There would be a helper class on my site that would pull a link based on an alias, give it attributes based off of the meta data (including microformatting), and spit out a final link. No where on ...

read more »

Abstracting the Resume

Recoding all of my subdomains to follow a model-view-controller framework has been a really interesting process. I've had the opportunity to experiment with different design patterns and techniques, especially in the realm of data handling and content delivery. Abstracting out my resume is a great example of how I'm handling my data in a way that provides necessary functionality at the moment while staying flexible enough for future rewrites.

Until recently my resume was written inline with html tags, merely included into different web pages as needed. This was a bad solution - every time I wanted to change a piece of it I had to wade through html tags. I couldn't place any dynamic content in my resume or reuse it in non-html formats. A cleaner solution was needed.

My first step was to divide up my resume into pieces. I have five main categories: objective, job history, skills, achievements, and education. The objective is a single line of text while the other four categories are lists. Some of these lists are lines of text while ...

read more »

Thoughts on Data Abstraction

Something that I've been working on a lot with both my work and personal web programming is data abstraction. The opportunity to work with several different handmade php frameworks has given me different ideas on what an effective data abstraction system should have. Without formal education, though, this post will be only based on my hands-on experience with the functionality I find myself using without true design patterns.

Data abstraction is a fancy word for treating the data as a separate entity from your web application logic. Web sites usually store their data in databases, using customized queries to pull information for their code to output and manipulate information. It doesn't matter what type of database or language you're working with; data abstraction can be employed whenever there is interaction with data (this post will be approaching this from a rough PHP - MySQL angle). Complex sites often have numerous queries scattered throughout the web site, and one needs to have intimate knowledge of the database structure during the ...

read more »

The Problem with Assuming

In the days of old (PHP 4) web programmers sometimes resorted to small shortcuts in their code. One of these was register_globals, which extracts the global arrays ($_REQUEST, $_POST, etc) into individual variables, allowing a programmer to write $name instead of $_POST['name']. This is an obvious security flaw - users can easily pass in custom parameters to overwrite variables in the code and cause unforeseen problems. In the below example, if register_globals was turned on in the PHP configuration, a tricky user can pass in a 'access' parameter and do some horrible things.

if($level == 'admin')
{
  $user = 'admin';
  $access = 'everything';
  $restrictions = 'none';
}

if($access == 'everything')
{
  // do some horrible things here
}

This is a good example of a bad programming practice - assuming that things will work the way you expect them to. That is, you assume that a level of 'admin' is the only way the 'access' variable could be set to 'everything'. The security-orientated approach would be to ...

read more »