I'm struggling to understand how I should achieve a decent error-handler at frontend (serverside). The code is written in functions.php in a specific theme (if that matters). Down below a custom post type named pupil is created upon submit.

$pupil = new Pupil();
add_shortcode('wppb-register', array($pupil, 'frontEndRegistration'));
//Check if visitor is trying to save a new pupil
$pupil->checkFrontEndRegistration();

If you wanted to access the errors on the form itself, I would personally recommend doing the error checking through JavaScript. This way, you can actually prevent the page from submitting, rather than submitting, cancelling, and redirecting back. With jQuery, it would be something like:

$('form').submit(function(event){
var $form = $(this);
// if any empty fields with the required class are found
if ($form.find('input.required:empty').length) {
event.preventDefault(); // cancel form submission
$form.find('input.required:empty').after('<p class="error">This field is required');
}
});

Obviously you could customize each field's message by reading the label attached to that input, or putting individual checks on each field. You can also work in some custom validation here, like Phone number validation, email, etc.

That's my preferred method.

For the PHP side, you should be able to store your error classes either on a class variable, or a global variable. Since the post.php page points back to itself, there is no redirection between your form submission checking, and re-rendering the page. You should be able to store the errors in a class variable and use it within both functions.

Thanks for your extended answer. I am actually doing that check in jQuery. But for safety I must have server-side validation as well. But I still didn't get the answer on my actual question :-) (How do I pass the actual errors from checkFrontEndRegistration() to the frontEndRegistration() ? (I mean class_errors would just be an empty array if there are nothing in array $errors that is specified)
–
bestprogrammerintheworldMar 17 '14 at 16:36

Good call - best practice should be to handle it on both ends. Extended answer 2.0 - in short, post.php points to itself, and handles the error checking early in the page load. so you can access your data later on :). Check it.
–
Eric HolmesMar 17 '14 at 18:03