Extra Office: how to save a extended field?

Hi all,

The documentation here explains how to show a extended field of a user.

But how can I save it the first time a user is filling a form?

[[!Office?
            	&action=`Auth`
            	&groups=`Customers`
            	&loginResourceId=`3`
            	&logoutResourceId=`22`
            	&HybridAuth=`0`
            	&profileFields=`username:50,email:50,fullname:50,mobilephone:12,address:20,city,zip,extended[company]`
            	&tplLogin=`shop.Office.auth.login`
            	&tplRegister=`shop.Office.auth.register`
            	&tplLogout=`shop.Office.auth.logout`
            	&tplActivate=`shop.Office.auth.activate`
            	&loginResourceId=`45`
            	
            ]]
and in the form:

<input type="text" name="extended[company]" placeholder="" class="form-control" id="extended.company" value=""/>

does not work.

Do I have to write a plugin that save this extended field?
Fabian Christen
14 марта 2018, 17:19
modx.pro
1 656
+1

Комментарии: 3

Василий Наумкин
14 марта 2018, 20:28
+1
Hello, Fabian! If you are talking about filling fields on registration, you need to create plugin for it, because Office do not require anything but email.

You can try to read it here. It is an example of selecting of user group, but requiring of extended field is very similar.
    Fabian Christen
    14 марта 2018, 22:04
    +2
    Thank you Василий Наумкин!

    It worked with:
    <?php
    
    $groups = array(
        'extendedcompany' => 'Company'
    );
    
    if ($modx->context->key != 'mgr') {
        switch ($modx->event->name) {
            
            case 'OnBeforeUserFormSave':
                if (!empty($_POST['extendedcompany'])  || array_key_exists($_POST['extendedcompany'], $groups)) {
                // etwas dem profil hinzufügen    
                $fields['company'] = $_POST['extendedcompany'];
                $user->Profile->set('extended',$fields);
                break;
                }
    
        }
        
    }
      Василий Наумкин
      14 марта 2018, 22:12
      +2
      Great!

      But I suggest you to check the state of your users:
      case 'OnBeforeUserFormSave':
      	if ($mode != 'new') {
      		return;
      	}
      	// ...
      break;
      Otherwise you could override their «extended» field on usual profile editing.

      And if you would like to update «extended», it is very easy too:
      if (...) {
      	$extended = $user->Profile->get('extended');
      	$extended['key'] = 'value';
      	$user->Profile->set('extended', $extended);
      }

      Now you know how to control any data of your users. With Office, or without it.
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    3