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?

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 march 2018, 17:19

Comments: 3

Василий Наумкин
14 march 2018, 20:28
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 march 2018, 22:04
    Thank you Василий Наумкин!

    It worked with:
    $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'];
      Василий Наумкин
      14 march 2018, 22:12

      But I suggest you to check the state of your users:
      case 'OnBeforeUserFormSave':
      	if ($mode != 'new') {
      	// ...
      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.
Log in or sign in to make new comments.