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?
does not work.
Do I have to write a plugin that save this extended field?
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?
Комментарии: 3
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.
You can try to read it here. It is an example of selecting of user group, but requiring of extended field is very similar.
Thank you Василий Наумкин!
It worked with:
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;
}
}
}
Great!
But I suggest you to check the state of your users:
And if you would like to update «extended», it is very easy too:
Now you know how to control any data of your users. With Office, or without it.
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.
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.