Jump to content

Input validation


dbo

Recommended Posts

I've just recently finished a project that required 60-80 fields per page on 8-10 forms and had to hand write javascript and php validation for this. I had written some libraries to assist in this... but even then it's a lot of work. So it got me thinking... there's got to be a much better way to do this. And so it began.....

 

The idea is to have a way to seperate business rules and validation rules from programming logic and have a shared set of rules for both php and javascript. Here is a code snipet to show you how much time/coding this type of framework could save you. I'm still in the early stages of development and have some issues to work through but this should give you the idea.

 

    include_once "xml_rule_validator.php";
    
    $xrv = new XMLRuleValidator();
    $xrv->load_from_file("xml_validation_rules.xml");
    
    $valid = $xrv->validate_php();
    
    if( !$valid )
    {
       $xrv->display_error_summary();
    }

 

And that's it... it would validate all get/session/post variables as specified in the xml document. So if you want to add or remove a check from a field... you make a simple change to an xml document rather than going in and hunting through lines of code. In my case I've got hundreds and hundreds of lines of code per page down to something like that.

 

So what are your guys thoughts? Do you have different alternatives that you think are better? Any improvements upon my idea?

Link to comment
https://forums.phpfreaks.com/topic/63846-input-validation/
Share on other sites

I bill hourly so it's actually less money on a per project basis... but this is also a small part of a much larger attempt at creating a rapid application development framework that works for me. The goal is to cut down projects that take 3-4 weeks to complete into a handful of days and really pound through more projects and/or work on more projects concurrently. The result is a consistent platform to do maintenance and more elegant, easy to read code. I'd venture to say that I spend upwards of 70-90% of development time validating input and doing error checking.

Link to comment
https://forums.phpfreaks.com/topic/63846-input-validation/#findComment-318455
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.