I'm inside module_form_alter(), switch ($form_id), case 'user_profile_form': and trying to get the uid of the user being edited. I can see several places within $form that it is available, but I'm unsure of whether they will always be there or what the best practice is for finding the uid.

Just as an example (and this isn't at all what I'm doing but it gives the scenario) here is some code that I'd like to have filled in. What should $form['#parameters'][2]->uid be?

module_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_profile_form':
      // Set $user_id equal to the uid of the user who's profile form is being displayed.
      $user_id = $form['#parameters'][2]->uid; // Replace this with ???
      break;
  }
} // function module_form_alter

This is what I'm using now, but I'm not certain that it is best practice and want to consult people who aren't doing it for their first time.

I greatly appreciate your help. :)

Comments

alim418’s picture

http://api.drupal.org/api/function/hook_user/6

you can use $op=='form' if you are trying to alter in user edit

The user value is in $account

arcaneadam’s picture

The comment above was talking about using hook_user in case you didn't realize that from what they posted. It will work a whole lot better.

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

mechler’s picture

Yeah, I've got it. Thanks, though. I was going to post acknowledging the reply yesterday afternoon but I was a bit busy at work.

Web Developer, Iowa State University College of Veterinary Medicine