Bitrix Site Manager

OnBeforeUserRegister event

bool
event_handler(
 array &arArgs
);

The OnBeforeUserRegister event fires before an attempt of a new user registration by calling the method CUser::Register. This can be used to cancel the registration process or redefine fields.

Parameters

ParameterDescription
arArgs Array of new user registration fields:
  • LOGIN - user login;
  • NAME - user first name;
  • LAST_NAME - user last name;
  • PASSWORD - password;
  • CONFIRM_PASSWORD - password confirmation;
  • CHECKWORD - new check word for password change;
  • 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.
Using this array, the system adds a user and sends an e-mail message NEW_USER.

Note
All parameters 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 to add additional user registration fields or a NEW_USER e-mail event fields to the array arArgs.

Return Values

To cancel the user registration and terminate the CUser::Register method, raise an exception from within the handler using the method $APPLICATION->ThrowException() and return false.

See Also

Example



<?
// file /bitrix/modules/my_module_id/include.php
class MyClass
{
    // create handler "OnBeforeUserRegister"
    function OnBeforeUserRegisterHandler(&$arFields)
    {
        // if a user came under the adv campaign #34...
        if ($_SESSION["SESS_LAST_ADV_ID"]==34)
        {
            // add him to group #3
            $arFields["GROUP_ID"][] = 3;    

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

            $arFields["SITE_ID"] = "ru";
        }
    }
}
?>

Example of handler registration


<?
// register handler "OnBeforeUserRegister"
RegisterModuleDependences("main", 
                          "OnBeforeUserRegister", 
                          "my_module_id", 
                          "MyClass", 
                          "OnBeforeUserRegisterHandler");
?>