Bitrix Site Manager

OnBeforeUserAdd

bool
event_handler(
   array &arParams 
);

The OnBeforeUserAdd event is fired from the CUser::Add method before a new user is enrolled (added to the database), which can be used to cancel enrollment or modify the user record fields.

Parameters

ParameterDescription
arParams An array of fields describing the user to be added.

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

Return Values

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

See Also

  • OnAfterUserAdd event
  • CUser::Add
  • Event handlers

    Example

    
    <?
    // file /bitrix/php_interface/init.php
    // register handler
    AddEventHandler("main", "OnBeforeUserAdd", Array("MyClass", "OnBeforeUserAddHandler"));
    
    class MyClass
    {
        // create the "OnBeforeUserAdd" event handler
        function OnBeforeUserAddHandler(&$arFields)
        {
            if(strlen($arFields["LAST_NAME"])<=0)
            {
                global $APPLICATION;
                $APPLICATION->throwException("Please type in the last name.");
                return false;
            }
        }
    }
    ?>