I’ve written a Form object (code: http://pastebin.com/U1xMRhdn) that validates whether information entered in a form field is valid or not. An example of it:
<?php
$f = Form(...);
//I would like to output the amount of errors up here.
$f->textBox(...);
$f->radioArea(...);
if($f->getErrors()>0)
echo "You have "+$f->getErrors();+" errors, go back and try again";
?>
If the user didn’t enter anything into the textbox the error counter increments.
The problem: I would like to display how many errors the user got wrong on top of the page. However, when I tried doing this the error counter retrieved 0 errors because the items had not yet been validated in functions textBox and radioArea. Is there a way to capture a value at the end of the script and return it to the top of the script? Or do I have to find another way of counting the errors?
Have you considered using output buffers?
Like so: