views:

162

answers:

1

When a user login , the user will be redirect to a user profile page, which has a My account field set.

the field set has 2 fields, "Username: ", "Email address:". those 2 fields are generated by drupal.

those 2 field contained in a form which has a id ("user_profile_form") . I want to change the order of those 2 fields.

I have tried to intercept 'user_profile_form' , inside hook_form_alter. code as follow: $form['account']['name']['#weight'] = 1;

but that did not success, drupal did not even rendering the 'name' field, so no username: showed on browser.

+1  A: 

What you did is absolutely correct, and probably did work. You can change the weight of the fields with the method described above.

The username field is not always rendered. The reason is that a persmission is required: change own username. If that perm is not set, you wont be allowed to alter you username and the field wont be shown.

Info on debugging.
Your info alone is not quite enough to debug. From what you describe, you are doing the right thing, but other modules could be making things a bit tricky for you. The devel module is quite good when it comes to debugging, ti defines two functions I use a lot when debugging:

  • dpm() pretty prints the variable to the message area using krumo.
  • dd() Prints / saves a variable to a log file. Useful when you can't view messages on the screen.

I would suggest that you look at the $form variable before and after you alter it.

Things that could make it go wrong:

  • Did you remember to pass the $form variable by reference using the & notation?
  • Is another module altering your form after you?
  • Are you checking for the correct form id, so you alter the correct form?

These are some pointers, before you bring more info, all I can do is guess to what your problem exactly can be. I did something like this a few days ago so I know what you describe shouldn't be a problem.

googletorp
i was working under admin account
anru
mac

related questions