How do you use profile_save_profile?
foreach ($users as $user) { //list of users to act on
$by_user = views_get_view_result('attendance', 'page_3', array($user->uid)); //view containing info about this user
$edit = array('profile_attendance_short_term' => substr(count($by_user) / count($general), 0, 5)); //calculation
profile_save_profile($edit, $user->uid, 'Fencing Information', TRUE); //update user profile???
}
What am I doing wrong?
EDIT: This also fails:
$edit = array('profile_attendance_short_term' => 9001);
profile_save_profile($edit, user_load(3), 'Fencing Information', TRUE);
I think the problem is that you're specifying $register
(the last parameter) as TRUE
. That is only used when creating new accounts, so if set, you will only be able to save the profile fields available on the registration page, which is probably not what you want.
Since it's not a required parameter, you can just leave it out.
When it comes to the format of edit, it expects the same format as the $form_state['values']
you would have if the values where coming from a form, for example:
<?php
$edit = array(
'fencing_style' => 'Aggressive',
'favorite_weapon' => 'sabre',
'left_handed' => FALSE,
);
profile_save_profile($edit, $user, 'Fencing Information');