PHP
  Home arrow PHP arrow Validating User Input with the Strateg...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Validating User Input with the Strategy Pattern
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-03-06

    Table of Contents:
  • Validating User Input with the Strategy Pattern
  • Building a validation strategy selector
  • Building some strategy classes
  • Validating user-supplied data
  • Listing all the classes required to implement the strategy pattern

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Validating User Input with the Strategy Pattern


    (Page 1 of 5 )

    The strategy design pattern is applied much more often than you might think, so if you want to find out how to implement it with PHP 5, this article should guide you through the whole learning process. Welcome to the final installment of the series that began with “Introducing the Strategy Pattern.” In two parts, this series walks you through the key points of how the strategy pattern works, and accompanies its theoretical concepts with copious hands-on examples.

    Introduction

    Going back quickly to the topics covered in the first tutorial of the series, certainly you'll remember that I explained the foundations of the strategy design pattern, and complemented the theory with some practical examples of how to apply this handy pattern in PHP 5.

    Based upon this scenario, I developed a set of simple PHP classes. One of them was defined as a strategy selector, handy for determining what type of format (HTML or XML) had to be applied to certain file data. The other ones were tasked with implementing a given formatting strategy.

    Although the example that I just described may seem rather basic, it shows in a nutshell the logic that drives the strategy pattern: on one hand there's a class that sets the context as to where a predefined group of strategies will be applied, while on the other hand there's one or more classes that implement  these strategies.

    However, now that you hopefully digested the contents of the first article of the series, let me tell you what you'll learn in this final tutorial. In the next few lines I'm going to demonstrate how to use the strategy pattern in a useful case, that is validating user-supplied input. Sound like an interesting experience, right?

    Now that you know the purpose of this last part of the series, let me show you how to implement the strategy pattern to check a wide range of user inputs. Let's begin now!

    More PHP Articles
    More By Alejandro Gervasio


       · This final tutorial of the series is focused on demonstrating how to use the...
       · Thank you very much for all your nice articles that I read carefully and enjoy so...
       · Thank you for your kind comments on my PHP article, since it’s something that I...
       · Thank you for your quick reply.I am not really sure that OOP is more scalable...
       · Thank you again for commenting on my PHP article. Definitively, OOP is best suited...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway