I searched the forums for existing discussions about this, but found nothing. In my module's implementation of hook_user, I need to take certain actions when op='update'. According to the API, I should "set the saved fields to NULL in $edit" if I want to prevent those values from being saved to the user's profile. The particular fields I'm interested in are four checkboxes, and regardless of whether they're checked or not, $edit contains NULL values.

If I print out the value of $edit as such...

function my_module_user($op, &$edit, &$account, $category = NULL) {  
  if ($op == 'update' && $category == 'The Category with the Checkboxes') { 
    drupal_set_message(print_r($edit, true));
    ...
  }
...
}

I get the following result...

Array ( [profile_checkbox_1] => [profile_checkbox_2] => [profile_checkbox_3] => [profile_checkbox_4] => [form_build_id] => form-31a6a5930fdb846034794ed1e2f6d452 )

The values of $edit are all null, whether I've checked those checkboxes or not. If I "set the saved fields to NULL in $edit" as the API says, it doesn't prevent the value of the checkboxes from being written to the user's profile. Also, it seems like I should be able to look at the $edit variable to see what edits are being submitted, but obviously I can't do that either.

What's going on here? I hope I'm not overlooking something obvious. Thanks in advance.

Comments

gpk’s picture

At a guess, possibly those checkboxes are or are being treated as profile fields, and profile.module is writing them to the user profile and setting them to NULL before your own module gets there. What is your module's machine name?

surgeonbor’s picture

Thanks for the reply. Those fields are profile fields, so that must be what's happening.

In that case, I guess I should use profile_save_profile to alter those fields? Or is there a different hook I should use to alter the profile fields before they're committed?

surgeonbor’s picture

For other people's benefit, yes, that was the problem, so I had to use profile_save_profile to alter the values that needed to be changed.

gpk’s picture

Glad you got to the bottom of it :-)

rschwab’s picture

Thanks for posting this. After understanding why $edit values were all null (my code is running for $op = 'after_update'), I just grabbed the data I needed from the {profile_values} database.