Prev |  | Next

### 3.15.6. before_register

This hook can be used for performing tasks before user registration. This hook is useful if you want to add some data to or change some data in the user data and to check if the user data is correct.
When checking the registration data, the hook can set the "error" field in the returned user data array. When this field is set after running the hook, the registration processed will be halted and the error will be displayed. If you created a custom form field "foo" and you require that field to be filled in, you could create a hook function like the one in the example below.
The error must be safely HTML escaped, so if you use untrusted data in your error, then make sure that it is escaped using htmlspecialchars() to prevent XSS (see also paragraph 3.6: Secure your pages from XSS).

Call time:

In `register.php`, right before a new user is stored in the database.

Hook input:

An array containing the user data of the soon-to-be-registered user.

Hook output:

Same as input.

Example code:

    function phorum_mod_foo_before_register ($data)
    {
        $myfield = trim($data['foo']);
        if (empty($myfield)) {
            $data['error'] = 'You need to fill in the foo field';
        }

        return $data;
    }

Prev | Up | Next
| Home |