We don't want users to edit any fields that are populated via the nightly EAA download (email address, zip code, expiration date, etc.), lest those changes be overwritten by our scripts. And obviously users shouldn't be allowed to extend their own membership expiration dates!
Some of these fields are part of the base user record, while others reside in the profile2 record that is associated with each user record.
Users can only modify those values using HTML edit forms. The Drupal API's hook_form_alter function allows the programmer to modify forms after Drupal generates them, but before they are rendered on the user's screen. So I added the following code to the $D7/sites/www.iac.org/themes/iac/template.php file:
/* Make the user's email field read-only, and remove the 'field required' asterisk for good measure */ function iac_form_user_profile_form_alter(&$form, &$form_state) { $form['account']['mail']['#required'] = FALSE; $form['account']['mail']['#disabled'] = TRUE; } /* Make certain profile2 fields read-only, and remove the 'field required' asterisks for good measure */ function iac_form_profile2_form_alter(&$form, &$form_state) { $form['profile_main']['field_iac_number']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_iac_number']['und'][0]['value']['#required'] = FALSE; $form['profile_main']['field_member_thru']['und']['0']['#disabled'] = TRUE;
$form['profile_main']['field_street_address']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_address2']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_city']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_state']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_zip_code']['und']['0']['#disabled'] = TRUE; $form['profile_main']['field_phone']['und']['0']['#disabled'] = TRUE;
}