By kc on
I have a question that was asked before and the answer to the question does not work.
I would like to disable user to edit his/her username on the edit page. I would like to display the text as a text but not make it a textfield and give the user the option to update it. How could I do that?
Thanks
Comments
i guess nobody is willing to help a non-php newbie
Well I tried couple suggestions like I said in prev post but having errors. Basically the problem is when you disable diplaying the username in user/edit page then when you try to submit the form it cannot find it and says username cannot be empty or something like that. Somehow the username info should be stored in a hidden form field and not displayed to the user but should be submitted along with other info when submit button is pressed. However I am not a PHP programmer and I cannot figure out how all that can be done.
I will really appreciate if someone can point me in the right direction.
koksal
You may need to include a ta
You may need to replace the existing form input with this:
<input type="hidden" maxlength="55" class="form-text" name="edit[name]" id="name" size="30" value="username" />
This is identical to the old input but is hidden and therefore not editable. It does however give the recipient script what it needs to di it's work.
almost there
Thanks for helping,
When I replaced the existing code like in the line below, with your line it hides the username but when you try to save the profile again it overwrites the existing username with the word "username" since the value provided is the string "username" instead of a variable.
I tried $username but did not work. How can I grab the username and stick into the value parameter?
Username into hidden field
The orignal input entry should have the variable for the username in it. You m ay need to crack open the distribution and check it if yo uhave overwritten the original, otherwise, I used this to get the username variable for apssing to other scripts.
global $user;
$name = $user->name;
Then use $name as the username value.
Cheers
thanks a lot it works now
I really appreciate it. It works now.
KC
Here is the file and line wit
Here is the file and line with the new code for anyone else who wants to do this.
I can't submit the < > characters, replace them where you see HERE
Update
This code does not allow for the possibility that another user like an admin can edit a users profile. In that case, the code looks like it will pull the admin's name from the $user object instead of the user's name. For this reason I have changed the code a little bit.
This code instead pulls the username from a separate user object, $user1. It uses the uid provided to the user_edit function.
This code is around line 1027 in my installation, drupal 4.52 but pretty heavily modified, so try this at your own risk.
in 4.6?
Hello everyone,
has this functionality (i.e. disabling editing of certain user profile fields) been built into 4.6 or would the above hack still need to be done?
If the latter, is it safe to assume that Fool2's code would work in 4.6 without modifications?
Thank you!
Re: in 4.6?
First, my english isn't as good as I wish (I speak spanish) so I would this comment will be usefull and understandable. I modified the user's module to let change the username field only by administrators, and to restrict this posibility to the normal users. I use the Fool2's code and insert a new line.
the changes were in user_edit_form function, line 1039 for 4.6, in this way:
comment line 1040:
$group = form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), NULL, TRUE);
insert lines:
$group = ""; //Inicializa la cadena por si es un administrador
if(!user_access('administer users')){ //No es administrador, por lo que no puede modificar su username
$inputarray['uid'] = $uid;
$user1 = user_load($inputarray);
$group = "name."\"/>";
}
insert the following line after line number 1044 (in original file)
$group .= form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Your full name: only letters, numbers and spaces are allowed.'), NULL, TRUE);
Bye
Juan Pablo Caballero Villalobos
Alumni Director Engineering Faculty
Pontificia Universidad Javeriana
Bogotá, Colombia
simpler way?
I found the following to be a slightly simpler way to do this. Replace line 1044 (first line in user_edit_form) with:
Additional Functionality
I realize this thread is pretty much dead (16 months old), but I thought I'd give this a try anyway.
Total newbee. Boss has mandated that all usernames are shown on posts as first/last name from profiles. My initial thought is to add a function that takes the UID, hits the db, concatenates the first/last names, and stuffs the result into $name variable.
I've searched, but haven't found this sort of hack. To make matters worse, my deadline is on this project is 12/30... and did I mention, total newbee?
drupaldocs is your friend
http://drupaldocs.org/api/4.6/function/profile_load_profile
Truth
Thank You! Working on it now...