Readme.txt for: FormValidator

 
========
FormValidator

PHP [5]
release: 1.0
========

Simple, lightweight, crappy, form validation. Loosely based on HTML_QuickForm's 
validation API. I originally wrote this because I had nothing with which to 
validate forms when using the Zend Framework. Seeing how excellent the 
FormEncode project worked with Pylons, I was inspired to make a pseudo-port to
PHP, and then I realized how much work it would be and wrote this instead.

Permission was granted from the author of FormEncode (Ian Bicking) to use the
regular expressions that FormEncode's Email validator uses.

========
Usage
========
Check out test.php which is included in the zip file.

An element may theoretically have more than one rule, but I couldn't find any
real need for this, i.e. an email rule implies a required rule, so there's no
point in specifying both.

========
API
========

- Constructor -
FormValidator::FormValidator( [name] )
	* name parameter is optional. Was originally going to be built to handle 
	  multiple forms or something. I'm not really sure what I was thinking. 
	  May be removed in the future.

- Validators - 
FormValidator::required(element, message)
	* Element cannot be empty. More specifically, since empty means something 
	  else in PHP, it cannot have a length of 0.

FormValidator::email(element, message)
	* Element must be a valid email format. Doesn't do any domain checking or 
	  anything like that.

FormValidator::in(element, message, (array) search)
	* Element value must be in search. Uses PHP's array_search function.

FormValidator::date(element, message)
	* Element must be a valid date format. Uses PHP's strtotime function, so
	  check that for what constitutes a valid date.

FormValidator::numeric(element, message)
	* Element must be a number.

FormValidator::regexp(element, message, regex)
	* Element must match regex (PCRE). Uses preg_match function.

- Everything Else -
FormValidator::validate((array) form_input)
	* Perform validation check. Form must have 0 errors to be considered valid.
	  Fields without rules are ignored completely.
	* returns: true or false

FormValidator::isValid()
	* Checks whether or not there are errors present without running 
	  validation.
	* returns: true or false

FormValidator::getErrors()
	* Get the list of all errors in the form
	* returns: array

FormValidator::getFirstError()
	* Get the error of the first invalid element
	* returns: string

FormValidator::addRule(element, rule, message [, parameter])
	* Validators are a wrapper for this method. Valid rules are the same names
	  as the methods.

FormValidator::removeRule(element [, index])
	* Remove a rule from an element via index or remove all of an element's
	  rules by setting index to -1 or omitting it.

========
http://mattptr.net