PHP Classes

Validation

Recommend this page to a friend!

      HtmlForm PHP 5  >  All threads  >  Validation  >  (Un) Subscribe thread alerts  
Subject:Validation
Summary:Use for validation only
Messages:3
Author:Michael Reid
Date:2011-08-21 09:34:47
Update:2011-08-22 11:20:06
 

  1. Validation   Reply   Report abuse  
Picture of Michael Reid Michael Reid - 2011-08-21 09:34:52
I am a relative novice with OO PHP and this package looks big. Before I work my way through it, I wonder if it is a silly idea to try to use this for validation of form results only (which is all I am actually looking for at the moment because the forms are already made and I am happy to extend them by hand)?

  2. Re: Validation   Reply   Report abuse  
Picture of Sebastian Schlapkohl Sebastian Schlapkohl - 2011-08-21 16:46:13 - In reply to message 1 from Michael Reid
Theoretically that should be possible. You could include the class htmlform.formvalidator.class.php and use it stand alone since as far as I can see the class has no forced external dependencies to the package, except for the tools class which should lie next to the validator class.

However you would practicall have to do by hand what the framework normally performs by itself.

This would be a rough use case:

require_once 'htmlform/htmlform.formvalidator.class.php';

$isFieldXyValid = FormValidator::get()
->setValue($_POST['myfieldname'])
->setNotEmpty()
->setRangeLength(array(1, 10))
->setDigits()
->process()
;

After this the var should contain a boolean telling you if your value is valid according to the set rules.

I never used the validator this way, but in this should indeed work quite well :D

For your plan I would recommend to write a small validation wrapper to streamline validation such as:

$isResultsetValid = ValidationWrapper::get()
->addValidator(FormValidator::get()->etc.)
->addValidator(FormValidator::get()->etc.)
->validateAll()
;

If you get my idea.

Good luck!

  3. Re: Validation   Reply   Report abuse  
Picture of Michael Reid Michael Reid - 2011-08-22 11:20:06 - In reply to message 2 from Sebastian Schlapkohl
Thanks very much for that helpful response. Will give it a try.