By manuel garcia on
I've been struggling these past two days trying to print the user profile form on a custom node, however I cannot seem to get it right.
I have tried printing drupal_edit_form:
// THIS kinda works, but no submit button
global $user;
$uid = $user->uid;
foreach ($user as $key => $value) {
$account[$key] = $value;
}
print(drupal_get_form('user_edit_form', $uid, $account));
// no success either
global $user;
print module_invoke('user', 'form', $user, 'account'));
Trying to print user_profile_form also returns an empty form... I'm kind of puzzled by this problem, has any one ever gotten this to work?
Comments
How about this: <?phpglobal
How about this:
call to undefined function
Thanks for the input mattyoung, didn't think of that :)
However, that gets me fatal error call to undefined function for some bizarre reason.
I checked the user_view api page, and did what that function does in my code directly, like:
Which works, but just gets me the user profile page, no user edit form. Interesting, perhaps useful to some, but not in our case unfortunately...
I have investigated a bit more, and according to the api, user_edit() returns the user_profile_form, but I just cant seem to use it properly. If i do:
I get an empty form like this:
So it seems that's the right form to call, only it's not geting populated with anything. I have a feeling I am missing a step before i call drupal_get_form here. Anyone has a clue what could it be?
The function is in
The function is in user.pages.inc which is not automatically loaded by the module system. So do this:
A quick question?
Are you getting "Save" and "Delete" buttons when you use drupal_get_form('user_profile_form', $account, $category);
and have you simply tried:
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
drupal_get_form doesn't work in this case it seems
If i do:
I just get an empty form like this (in the source):
So the only way seems to be including user.pages.inc and then call user_edit directly. Why I don't know, since user_edit() basically does the same thing. Something for an X-files episode?
Success!
OK guys, here is how to go about doing this:
I've included a check for a logged in user, because otherwise it will still show the form, with no values in it, which is definitely not what you'd want.
Anyway, thanks SO much for your help, I knew there must be a way... <3 Drupal!
Correction / explanation
OK, looks like drupal_get_form('user_profile_form', $user) will only work properly if you have previously included user.pages.inc.
So, if you don't want the page title to be set to the user name (done in user_edit), you would go about doing it like this:
And that gets you just the form itself, populated and with all the buttons.
Again, thanks all for your help!
I came across this thread and
I came across this thread and tried the above and it worked perfectly! Thank you-
I have an additional question if someone can help:
Is it possible to just print one of the fields from the user profile form? for example the 'Email' input field?
I would appreciate your help!
Better way to include a drupal module
There is a better way to include a drupal module
Look at
http://api.drupal.org/api/function/module_load_include
Kind Regards
Andres Yajamin
Very true, thanks!
Very true, thanks!
I had to change one thing
I had to change one thing about this:
to
With print, we bypass the theme rendering. Return builds the form in the theme as expected.
Thanks, drupal community!
This worked just like I needed!
Doesnt work for a custom profile edit
If you try to use the above code in a customized version of the user_edit_profile template it will not work as it sends you into an endless loop.
ANy ideas how to do it in that case?
Print CCK form?
This snippet works great for the profile form but can this be applied to a cck form as well? Do you know what I would have to change in the 'drupal_get_form'(if that's even correct) to get it to print a cck form anywhere on a site?
custom node
Hi Manuel
How did you managed to redirect user edit form to a custom node?
I'm using a my own theme and when I try to edit the users profiles I receive a empty form, like in the one of the comments.
I wasn't be able to fin out the reason, but probably using a custom node will be a good workaround.
How to print the user profile form with category anywhere? (D6)
If you configured extra profile fields like, first name, last name, address, etc... under category "Registration Information" while using core profile module then it would be very easy for you to print edit profile form (Registration Information ) on any node, just use the below code in drupal 6.
Missing form tags and input fields
When I use this code, the labels of my form are displayed. However, the page doesn't show the input fields and the source doesn't have form tags. Any ideas where to debug this?
User profile editing form in a block in Drupal 7
In case anyone trying to do this in D7 stumbles across this page, here's how to render the user profile form in a PHP block:
Doesn't populate fields
I've tried the code above and many other things but I just can't seem to populate the fields with the user's information. The username and email populate but all the other fields don't. If I got to 'user/uid/edit' the fields are there with data in them. Any ideas?
Edit: I was being stupid, for anyone else like me remember to user_load after global $user ;)
The example by rmathew will
The example by rmathew will only work if you have no custom fields. If you have custom fields then it's:
Note that that will throw a
Note that that will throw a PHP warning. To get rid of the warning, you should do this:
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for this!
Thanks for this!