handler function(
 array &arArgs
The event "OnBeforeUserRegister" is called before a new user registration attempt by the method CUser::Register and can be used to terminate the registration process or to re-define specific fields.

Note: function will be called also when registration is confirmed (event OnBeforeUserUpdate), where the LOGIN key is unavailable.


arArgs Array of registration fields for new users:
  • LOGIN - user login;
  • NAME - user name;
  • LAST_NAME - user last name;
  • PASSWORD - password;
  • CONFIRM_PASSWORD - password confirmation;
  • CHECKWORD - new checkword to change password;
  • EMAIL - user e-mail;
  • ACTIVE - active state flag [Y|N];
  • SITE_ID - the ID of default site used for notifications;
  • GROUP_ID - array of user group ID's
  • USER_IP - user IP address;
  • USER_HOST - user host name.
User is added and NEW_USER mail event is sent based on the array of fields.

Note Array of values passed to this handler function are references to original variables. Therefore, all changes to parameters made within the handler affect values of the original variables.

This allows, for example, to add additional new user registration fields or fields for NEW_USER mail event into the array arArgs.

if ( isset($args['LOGIN']) && ! preg_match("/^[-a-zA-Z0-9_]+$/", $args['LOGIN']) )

Returned value

To cancel user authorization and terminate the execution of the method CUser::Register, throw an exception by the method $APPLICATION->ThrowException() and return false.

See Also

Example of handler function:

// файл /bitrix/modules/my_module_id/include.php
class MyClass
    // cre ate   event handler "OnBeforeUserRegister"
    public static function OnBeforeUserRegisterHandler(&$arFields)
        // if a user came under the adv campaign #34,
        if ($_SESSION["SESS_LAST_ADV_ID"]==34)
            // add this user to group #3
            $arFields["GROUP_ID"][] = 3;    

            // add admin comment  
            if (intval($_SESSION["SESS_ADV_ID"])>0)
                $arFields["ADMIN_NOTES"] = "Ad campaign #34 - direct visit";
                $arFields["ADMIN_NOTES"] = "Ad campaign #34 - return";

            $arFields["SITE_ID"] = "ru";

Example of handler function registration:

// register the event handler "OnBeforeUserRegister"
RegisterModuleDependences("main", "OnBeforeUserRegister", "my_module_id", "MyClass", "OnBeforeUserRegisterHandler");

© «Bitrix24», 2001-2023