Recommend this page to a friend! |
Classes of Jonas Earendel | Simple Form Validator | README.md | Download |
|
DownloadSimpleFormValidatorThe purpose of SimpleFormValidator is to make user input validation secure, simple and fast. No external rule declarations are necessary, or even possible. SimpleFormValidator will instead extract the rules from the HTML using PHP's native DOMDocument class. Just make sure you have valid HTML5 code, and it will work. THE INGREDIENTSThree ingredients are needed to make it work:
A BASIC EXAMPLEThe smallest example imaginable:
>$_POST['your_email'] will be validated as an e-mail address. $_POST['your_email'] cannot be left empty. $_POST['repeat_email'] must match $_POST['your_email'], whether empty or not. CUSTOM ERRORSSo, the user has entered a valid username and password, but they aren't correct. That's when custom errors (triggerCustomError()) come in handy.
PRESET VALUESIf for instance a user is logged in and wants to send an e-mail, you can pre-populate the form. (This saves a lot of time during development.)
EXTENSIBILITYThe base class does not have that many validators, just the ones I've had use for lately, but that is not the end of the story. Enter: Inheritance. Create your own class, extending SimpleFormValidator, and add the validators you want. The existing ones can all be found in the original's constructor, if you need hints. Like so:
I do not recommend editing SimpleFormValidator directly, since there may be updates in the future. |