I am trying to find a good expandable way to validate all my forms.
3 basic steps I want here.
Next to the field the rules are defined. For instance
noNull, Max12, etc
<input type="text" name="name">
noNull, etc
<input type="text" name="type">
Next when the form is processed it would check all the rules on each element.
Finally if it doesn't pass validation it will output the form again with an error message next to each form.
Now what I was able to do: What I tried was I made some static methods that accepted a string. If it fails the test it sets $validate = false Then I called them when it validates like this.
if ($_POST['submit'])
{
FormCheck::notNull;
FormCheck::etc;
if ($validate = true)
{
input into database
}
}
Now the problem is first the rules are put where form is processed. I would like the rules to be next to each form element. Next I had no clue how to get the error messages to print out correctly. I'm assuming you would use error exceptions?
Any ideas that can give me some leads? I've never really done anything horribly complex in php and don't know how to use much of the advanced stuff.