seanzol Posted September 9, 2015 Share Posted September 9, 2015 I'm attempting to access and update a user's profile field from within a page, using the following code:$member = \IPS\Member::loggedIn(); $fields = $member->contentProfileFields(); $fields['core_pfieldgroups_3'][3] = implode(',', $to_save); $member->save();However, these changes aren't actually committed back to the database. What am I doing wrong? Link to comment Share on other sites More sharing options...
TSP Posted September 9, 2015 Share Posted September 9, 2015 Profilefields are not updateable through $member->save() as far as I know. Looking at how it's done in applications/core/modules/front/members/profile.php it seems you need to go about it this way: $member = \IPS\Member::loggedIn(); $fields['member_id'] = $member->member_id; # Example 1 where you also make use of the previous value to set the new value in some way $originalFields = $member->profileFields(); $fields['field_3'] = $originalFields['core_pfieldgroups_1']['core_pfield_3'] . " Append this text."; # Example 2 where you simply update it with the implode for your $to_save-variable: $fields['field_3'] = implode(',', $to_save); \IPS\Db::i()->replace( 'core_pfields_content', $fields );Obviously you'll need to identify the pfieldgroup and pfield id that is relevant for you. Link to comment Share on other sites More sharing options...
seanzol Posted September 20, 2015 Author Share Posted September 20, 2015 On 9/9/2015, 6:48:10, TSP said: Profilefields are not updateable through $member->save() as far as I know. Looking at how it's done in applications/core/modules/front/members/profile.php it seems you need to go about it this way: $member = \IPS\Member::loggedIn(); $fields['member_id'] = $member->member_id; # Example 1 where you also make use of the previous value to set the new value in some way $originalFields = $member->profileFields(); $fields['field_3'] = $originalFields['core_pfieldgroups_1']['core_pfield_3'] . " Append this text."; # Example 2 where you simply update it with the implode for your $to_save-variable: $fields['field_3'] = implode(',', $to_save); \IPS\Db::i()->replace( 'core_pfields_content', $fields ); Obviously you'll need to identify the pfieldgroup and pfield id that is relevant for you. Oops, forgot to hit notify me, thank you so much! I ended up doing it manually like I did in 3.4, but I'd like to switch over to the proper way haha Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.