Documentation

Update

Description and parameters

mixed
CSubscription::Update(
    int ID,
    array arFields,
    string SITE_ID = SITE_ID
);

Method updates subscription data. In case of updating subscription address, the method removes confirmation from subscription and generates an event for sending an email with subscription confirmation code (if not directly restricted). If subscription isn't confirmed and array with fields includes a correct CONFIRM_CODE, then the subscription is confirmed. Non-static method.

Parameters

ParameterDescriptionAvailable from version
ID Subscription identifier.
arFields array with values for "Subscription" object fields. Additionally, can specify the following fields:
   RUB_ID - array with newsletter IDs, that this address subscribes;
   SEND_CONFIRM - sends a confirmation code email to subscriber when updating the address (Y/N).
SITE_ID Site identifier used to define template for subscription confirmation email. By default, this parameter receives current site value. Required when using RUB_ID. In case, if ALL_SITES is specified in array $arFields, then SITE_ID may be skipped and not specified

Returned value

Returns true on success. Otherwise returns false, and LAST_ERROR variable class contains an error message (also throws exception CMain::ThrowException).

On successful result, LAST_MESSAGE class variable contains string-code for information message. Possible values:
   "CONF" - subscription confirmed;
   "SENT" - generates event for sending email with confirmation code.

Example

$subscr = new CSubscription;
//confirmation code from letter or confirmation form
if($CONFIRM_CODE <> "" && $ID > 0 && empty($action))
{
    if($str_CONFIRMED <> "Y")
    {
        //subscribtion confirmation
        if($subscr->Update($ID, array("CONFIRM_CODE"=>$CONFIRM_CODE)))
            $str_CONFIRMED = "Y";
        $strWarning .= $subscr->LAST_ERROR;
        $iMsg = $subscr->LAST_MESSAGE;
    }
}

//*************************
//form actions processing
//*************************
if($ID > 0)
{
    if($action == "unsubscribe" && CSubscription::IsAuthorized($ID))
    {
        //unsubscription
        if($subscr->Update($ID, array("ACTIVE"=>"N")))
        {
            $str_ACTIVE = "N";
            $iMsg = "UNSUBSCR";
        }
    }
    if($action == "activate" && CSubscription::IsAuthorized($ID))
    {
        //activation
        if($subscr->Update($ID, array("ACTIVE"=>"Y")))
        {
            $str_ACTIVE = "Y";
            $iMsg = "ACTIVE";
        }
    }
}

© «Bitrix24», 2001-2024
Up