XF 2.0 Read actual error

GPA-R

Active member
Hi,

I am running a custom script outside XF to register users. It works however there's a issue. If for any reason the registration fails, I cannot show the user any message regarding the error.

Taken from the default controller:
PHP:
if (!$registration->validate($errors)){
        # blah blah
}

$errors is an object that contains protected properties which I cannot access in order to read the actual error and return to the user. For example if a username is already in use etc. Is there a class which parses this? What is the right way of doing it?

Any ideas?

Thanks in advance
 
$errors should just be an array of strings. At worst, it could be an array that contains one or more phrase objects.

There’s a few approaches but if you want to display all errors then you should loop through the array and run strval() on each item to get the error messages.
 
My custom registration only passes a username/email so I decided to take a different approach than reading the $error. I check if an account exists with the provided username/password and display an error accordingly before passing anything to $registration. If there's any other error during the registration a generic message is shown to the user.

Logically speaking that should be ok.
 
Back
Top Bottom