All,
I'm working on the server side data validation for LS 2.0 and wanted to solicit your feedback on the architecture.  I have started documenting it in a wiki page at http://docs.limesurvey.org/tiki-index.php?page=Data+Validation+Code+Architecture which is linked from the main development wiki (http://docs.limesurvey.org/tiki-index.php?page=LimeSurvey+2.0+Development).  I still need to add more usage examples and describe the LS tie-in.  The one explicit question I have:  Is there a preference on default behavior when attempting to validate a variable which is null or empty string?  Should it return true (passed validation), false (failed validation), or throw an error?  The behavior will be configurable, but I will have to specify a default behavior.

thanks,

-Jim

Data Validation Code Architecture

(cached)
Some surveys may require certain criteria be met when answering a question. Examples: "this answer must be an integer between 5 and 10", "this string must be no more than 12 characters", "this date must be entered in mm/dd/yyyy format". For convenience and user feedback, answers will be validated on the client side using the Dojo toolkit when possible. The data, of course, must also be validated on the server side before it is saved to the database. The underlying validation library was developed specifically to support LimeSurvey 2.0, and the code architecture is described in a separate wiki page.




Overview

The validation code will be written as a separate library which can be used generically to validate data. The library will be dropped into the Cake "vendors" directory in the Lime Survey 2.0 codebase, where Lime Survey will be able to use it for validation. The library will be provided with a full set of unit tests using the SimpleTest framework.

Validation Architecture

The validation library, which I've called "ezval", will consist of:

The current plan is to only provide the following three classes of validators initially:

Some default expressions will be provided, so that a developer may use ezval constants instead of hand-coding their own expressions, which can sometimes be error-prone especially with regular expressions. The behavior for null or empty values will be configurable, but by default will...

Tie-in to Lime Survey 2.0


Usage and Code Examples

    // the following are all valid invocations
    $validator = new RegexpValidator();
    $validator->validate("15", "/^(\+|\-){0,1}[[:digit:]]*$/");




--

============================================
    James A Barkley
    Senior Computer Systems Engineer (AC3)
    MITRE Open Services (E542)
    M Building
    202 Burlington Rd.
    Bedford MA 01730
    United States
    O: 781.271.7017
    C: 303.579.2274
    Email: jbarkley@mitre.org
    "If it is complex, make it simple. If it is simple, excel at it. If it is mundane, automate it."
============================================