A
A
Alexander Ivanov2016-07-11 11:51:16
PHP
Alexander Ivanov, 2016-07-11 11:51:16

How to save changes in custom field?

Registration page. The bitrix:main.profile component.
Displaying a custom field:

global $USER;
  $arFilter = array("ID" => $USER->GetID());
  $arParams["SELECT"] = array("UF_VK");
  $arRes = CUser::GetList($by,$desc,$arFilter,$arParams);
  if ($res = $arRes->Fetch()) {
    echo "<p><span>Адрес страницы вконтакте</span><br /><input type='text' name='NAME' maxlength='50' value='".$res["UF_VK"]."' /></p>";
  }

Save button:
<p><?echo $arResult["GROUP_POLICY"]["PASSWORD_REQUIREMENTS"];?></p>
  <p><input type="submit" name="save" value="<?=(($arResult["ID"]>0) ? GetMessage("MAIN_SAVE") : GetMessage("MAIN_ADD"))?>">&nbsp;&nbsp;<input type="reset" value="<?=GetMessage('MAIN_RESET');?>"></p>

Apparently update is responsible for this, but it's not entirely clear how to use it.
https://www.youtube.com/watch?v=OsmfPWc24X0
I noticed such a feature, in the official example https://www.youtube.com/watch?v=Zn35MdRADEY , developers
add a field and customize it. However, in mine there will be about 10 foreach, which is not cool at all. However, now it is clear where to go:
<?// ********************* User properties ***************************************************?>
  <?if($arResult["USER_PROPERTIES"]["SHOW"] == "Y"):?>
  <div class="profile-link profile-user-div-link"><a title="<?=GetMessage("USER_SHOW_HIDE")?>" href="javascript:void(0)" onclick="SectionClick('user_properties')"><?=strlen(trim($arParams["USER_PROPERTY_NAME"])) > 0 ? $arParams["USER_PROPERTY_NAME"] : GetMessage("USER_TYPE_EDIT_TAB")?></a></div>
  <div id="user_div_user_properties" class="profile-block-<?=strpos($arResult["opened"], "user_properties") === false ? "hidden" : "shown"?>">
  <table class="data-table profile-table">
    <thead>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
    </thead>
    <tbody>
    <?$first = true;?>
    <?foreach ($arResult["USER_PROPERTIES"]["DATA"] as $FIELD_NAME => $arUserField):?>
    <tr><td class="field-name">
      <?if ($arUserField["MANDATORY"]=="Y"):?>
        <span class="starrequired">*</span>
      <?endif;?>
      <?=$arUserField["EDIT_FORM_LABEL"]?>:</td><td class="field-value">
        <?$APPLICATION->IncludeComponent(
          "bitrix:system.field.edit",
          $arUserField["USER_TYPE"]["USER_TYPE_ID"],
          array("bVarsFromForm" => $arResult["bVarsFromForm"], "arUserField" => $arUserField), null, array("HIDE_ICONS"=>"Y"));?></td></tr>
    <?endforeach;?>
    </tbody>
  </table>
  </div>
  <?endif;?>
  <?// ******************** /User properties ***************************************************?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ivanov, 2016-07-11
@cimonlebedev

It's easiest like this:

<?
if ($arResult['DATA_SAVED'] == 'Y' AND $arResult["USER_PROPERTIES"]["SHOW"] == "Y")// заменяю иф в самом начале
  ShowNote(GetMessage('PROFILE_DATA_SAVED'));
?>

then I delete all the User properties code, and output it like this:
<input type="text" name="UF_VK" maxlength="255" value="<?=$arResult["USER_PROPERTIES"]["DATA"]["UF_VK"]["VALUE"]?>" />

A
Adminchik, 2016-11-22
@Adminchik

Is it possible to somehow just use User properties in the registration module?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question