I am using a registration class to process a registration form and need
some opinions on returning error messages.
I am self referring the page on submit.
I would like to send each form field to the class for processing
(validating, sanitizing, etc..) So far no problem.
Now I am throwing ideas around on how best to check for error messages
to the users.
One idea was to expect and array from the class as a return value, set
the error key in the function if needed and check if the error key is
set for each call.
public function validateEmail($post) {
//if no error after validating
$result['result'] = $post;
return $result
//if error
$result['error'] = 'Please input a valid email';
return $result;
}
$result = $register->validateEmail($_POST['email']);
if(isset($result['error'])){
//process for display
} elseif(isset($result['result'])) {
//process for DB
}
************************************************** ***************
Second idea was to use a PUBLIC variable in the class and test it.
public $error;
public function validateEmail($post) {
//if no error after validating
$result = $post
return $result;
//if error
$this->$error['email'] = "Please enter a valid email";
}
$result = $register->validateEmail($_POST['email']);
if(isset($error['email]){
//process for display
} else {
//process $result
}
************************************************** ****************
I have only tested the first idea and it has worked so far.
I am still learning OOP so the second idea may not even be good practice
or might not even work as predicted.
I know some of you out there have come across this and am curious what
has worked for you.
Thanks
Scotty