Prevent users changing "Name" in "Edit Your Profile"
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
-
- Joomla! Fledgling
- Posts: 3
- Joined: Sat Sep 10, 2011 10:16 pm
Prevent users changing "Name" in "Edit Your Profile"
I've just spent the best part of Saturday evening looking how to disable users from changing their Name in the Edit Your Profile in 1.7, but just can't find out how to do it, or which file to hack to make the field protected/readonly. Pleeese could someone point me in the right direction.
-
- Joomla! Ace
- Posts: 1460
- Joined: Sat Jan 21, 2006 8:42 pm
Re: Prevent users changing "Name" in "Edit Your Profile"
/components/com_user/views/profile/tmpl/edit.php
edit this file or create an override in your template
edit this file or create an override in your template
- jmuehleisen
- Joomla! Virtuoso
- Posts: 4874
- Joined: Thu Nov 09, 2006 2:46 pm
- Location: Kampala, Uganda
- Contact:
Re: Prevent users changing "Name" in "Edit Your Profile"
One of the challenges here will be that the /components/com_user/views/profile/tmpl/edit.php file doesn't handle each field in the profile individually ... it takes the approach of "loop through all of the fields and put them up there for editing."
So, the question then becomes, where is it getting the list of field names to put up there?
And the answer is, in this file:
This file lists each of the fields in the user profile and defines how they should be handled when doing an "edit your profile."
If you look in this file around line 11 you will see the definition for "Name:"
You can change the "type" from "text" to "hidden" and that will make this field not even show up on the User Profile screen and it will be not editable.
So, for example change the code to this:
And actually, most of the code after the "hidden" is not needed any more, but leave it there anyway in case you decide to change things back later.
Now another option, which might even be better, is to simply make the name "read only." To do that, add the code to the file, like this:
Now, the problem with this "hack the Joomla core" approach is that there is the possibility that your edits may be overwritten with a future Joomla upgrade.
For layout modifications, this can generally can be overcome by using the "template overrides" approach but that doesn't quite work for a "model override."
This article says you can indeed override a model, but though the use of a custom written plug-in:
http://community.joomla.org/blogs/commu ... -html.html
But, I could not quite understand from the article on how to do that, so I can't give specific help on this part of the procedure.
But, to get back to your original question, changing one word in the models xml profile file or adding one line will do what you want to make the "Name" uneditable.
Code: Select all
34 <?php foreach ($fields as $field):// Iterate through the fields in the set and display them.?>
And the answer is, in this file:
Code: Select all
/components/com_users/models/forms/profile.xml
If you look in this file around line 11 you will see the definition for "Name:"
Code: Select all
<field name="name" type="text"
description="COM_USERS_PROFILE_NAME_DESC"
filter="string"
label="COM_USERS_PROFILE_NAME_LABEL"
message="COM_USERS_PROFILE_NAME_MESSAGE"
required="true"
size="30"
/>
So, for example change the code to this:
Code: Select all
<field name="name" type="hidden"
description="COM_USERS_PROFILE_NAME_DESC"
filter="string"
label="COM_USERS_PROFILE_NAME_LABEL"
message="COM_USERS_PROFILE_NAME_MESSAGE"
required="true"
size="30"
/>
Now another option, which might even be better, is to simply make the name "read only." To do that, add the code
Code: Select all
readonly="true"
Code: Select all
<field name="name" type="text"
description="COM_USERS_PROFILE_NAME_DESC"
filter="string"
label="COM_USERS_PROFILE_NAME_LABEL"
message="COM_USERS_PROFILE_NAME_MESSAGE"
required="true"
size="30"
readonly="true"
/>
For layout modifications, this can generally can be overcome by using the "template overrides" approach but that doesn't quite work for a "model override."
This article says you can indeed override a model, but though the use of a custom written plug-in:
http://community.joomla.org/blogs/commu ... -html.html
But, I could not quite understand from the article on how to do that, so I can't give specific help on this part of the procedure.
But, to get back to your original question, changing one word in the models xml profile file or adding one line will do what you want to make the "Name" uneditable.
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
-
- Joomla! Fledgling
- Posts: 3
- Joined: Sat Sep 10, 2011 10:16 pm
Re: Prevent users changing "Name" in "Edit Your Profile"
Thanks for your prompt and detailed replies!
- Sudhir_Dixit
- Joomla! Apprentice
- Posts: 14
- Joined: Fri Aug 13, 2010 8:24 am
Re: Prevent users changing "Name" in "Edit Your Profile"
Hi, jmuehleisen....
You saved me.....thanks for the detailed information...
thanks once again
You saved me.....thanks for the detailed information...
thanks once again

-
- Joomla! Apprentice
- Posts: 16
- Joined: Tue Oct 25, 2011 8:31 am
Re: Prevent users changing "Name" in "Edit Your Profile"
Thanks for such detail !
But i got want to make fields readonly for "User" Not for administrator. When i use the above hack it works perfectly but it is for users and administrator both. I want that only users can see and can not edit their profile.
But i got want to make fields readonly for "User" Not for administrator. When i use the above hack it works perfectly but it is for users and administrator both. I want that only users can see and can not edit their profile.
- jmuehleisen
- Joomla! Virtuoso
- Posts: 4874
- Joined: Thu Nov 09, 2006 2:46 pm
- Location: Kampala, Uganda
- Contact:
Re: Prevent users changing "Name" in "Edit Your Profile"
If you want this code to act differently based on if the user is an Administrator, you could try putting in an if structure.
Something like this, perhaps:
I'm not sure the code is exactly right for the if ... else but that would be the general idea.
Again, though, let me give the warning that this is a core hack that may be overwritten during a Joomla core update, so be sure to document what you do in case you need to re-apply the code changes.
Something like this, perhaps:
Code: Select all
$user =& JFactory::getUser();
if($user->usertype == "Super Administrator" || $user->usertype == "Administrator")
<field name="name" type="text"
description="COM_USERS_PROFILE_NAME_DESC"
filter="string"
label="COM_USERS_PROFILE_NAME_LABEL"
message="COM_USERS_PROFILE_NAME_MESSAGE"
required="true"
size="30"
/>
else
<field name="name" type="text"
description="COM_USERS_PROFILE_NAME_DESC"
filter="string"
label="COM_USERS_PROFILE_NAME_LABEL"
message="COM_USERS_PROFILE_NAME_MESSAGE"
required="true"
size="30"
readonly="true"
/>
Again, though, let me give the warning that this is a core hack that may be overwritten during a Joomla core update, so be sure to document what you do in case you need to re-apply the code changes.
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
-
- Joomla! Apprentice
- Posts: 16
- Joined: Tue Oct 25, 2011 8:31 am
Re: Prevent users changing "Name" in "Edit Your Profile"
ok i will try it and then answer you.
Sir ! i got a error while i login to joomla with wrong username and password. it display another page to me. I want to redirect user to specific page when username and password mismatches.
Sir ! i got a error while i login to joomla with wrong username and password. it display another page to me. I want to redirect user to specific page when username and password mismatches.
- jmuehleisen
- Joomla! Virtuoso
- Posts: 4874
- Joined: Thu Nov 09, 2006 2:46 pm
- Location: Kampala, Uganda
- Contact:
Re: Prevent users changing "Name" in "Edit Your Profile"
As you have found, Joomla does not allow you to specify the page to go to if a login fails.
There are several extensions to Joomla 1.5 that can do this, but I don't know of any for Joomla 1.7 yet. But, you can try looking here: http://extensions.joomla.org/extensions ... ite-access
There are several extensions to Joomla 1.5 that can do this, but I don't know of any for Joomla 1.7 yet. But, you can try looking here: http://extensions.joomla.org/extensions ... ite-access
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials: http://welcometojoomla.com
-
- Joomla! Apprentice
- Posts: 20
- Joined: Fri Jan 30, 2015 6:01 am
Re: Prevent users changing "Name" in "Edit Your Profile"
Sorry to bring back this old topic, but I am looking to add a field too the profile page where you can fiew a specific record, or coloum in the row for the user.
I want to be able to display the data for that users specific field, just as plain text (not editable),
I tried to do into the edit.php file in /public_html/components/com_users/views/profile/tmpl but the php I put in breaks the page. not sure how to access the database with out interfering with the flow of the components.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//select used to select from one or more tables
$query->select('name')
//from is the table
->from($db->quoteName('#__users'))
//where is the row
->where($db->quoteName('id').'=771');
$db->setQuery($query);
$my_value = $db->loadResult();
echo $my_value;
Although this code gets the name in theory, and even on the home page it works in a regular index.php file. When I try to insert it into edit.php the whole page breaks. Either it shows a page where it has the profile fields but nothing else (as in, no header, no banner no menu, literally a blank page with some input boxes) or the page doesn't show the profile, just blank in the content part.
I am novice and would like to know how to accomplish this.
Any help out there?
I want to be able to display the data for that users specific field, just as plain text (not editable),
I tried to do into the edit.php file in /public_html/components/com_users/views/profile/tmpl but the php I put in breaks the page. not sure how to access the database with out interfering with the flow of the components.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//select used to select from one or more tables
$query->select('name')
//from is the table
->from($db->quoteName('#__users'))
//where is the row
->where($db->quoteName('id').'=771');
$db->setQuery($query);
$my_value = $db->loadResult();
echo $my_value;
Although this code gets the name in theory, and even on the home page it works in a regular index.php file. When I try to insert it into edit.php the whole page breaks. Either it shows a page where it has the profile fields but nothing else (as in, no header, no banner no menu, literally a blank page with some input boxes) or the page doesn't show the profile, just blank in the content part.
I am novice and would like to know how to accomplish this.
Any help out there?
-
- Joomla! Apprentice
- Posts: 27
- Joined: Thu Jun 03, 2010 7:08 pm
Re: Prevent users changing "Name" in "Edit Your Profile"
This extension will help accomplish this: http://extensions.joomla.org/extension/ ... l-overridejmuehleisen wrote:One of the challenges here will be that the /components/com_user/views/profile/tmpl/edit.php file doesn't handle each field in the profile individually ... it takes the approach of "loop through all of the fields and put them up there for editing."So, the question then becomes, where is it getting the list of field names to put up there?Code: Select all
34 <?php foreach ($fields as $field):// Iterate through the fields in the set and display them.?>
And the answer is, in this file:This file lists each of the fields in the user profile and defines how they should be handled when doing an "edit your profile."Code: Select all
/components/com_users/models/forms/profile.xml
If you look in this file around line 11 you will see the definition for "Name:"You can change the "type" from "text" to "hidden" and that will make this field not even show up on the User Profile screen and it will be not editable.Code: Select all
<field name="name" type="text" description="COM_USERS_PROFILE_NAME_DESC" filter="string" label="COM_USERS_PROFILE_NAME_LABEL" message="COM_USERS_PROFILE_NAME_MESSAGE" required="true" size="30" />
So, for example change the code to this:And actually, most of the code after the "hidden" is not needed any more, but leave it there anyway in case you decide to change things back later.Code: Select all
<field name="name" type="hidden" description="COM_USERS_PROFILE_NAME_DESC" filter="string" label="COM_USERS_PROFILE_NAME_LABEL" message="COM_USERS_PROFILE_NAME_MESSAGE" required="true" size="30" />
Now another option, which might even be better, is to simply make the name "read only." To do that, add the codeto the file, like this:Code: Select all
readonly="true"
Now, the problem with this "hack the Joomla core" approach is that there is the possibility that your edits may be overwritten with a future Joomla upgrade.Code: Select all
<field name="name" type="text" description="COM_USERS_PROFILE_NAME_DESC" filter="string" label="COM_USERS_PROFILE_NAME_LABEL" message="COM_USERS_PROFILE_NAME_MESSAGE" required="true" size="30" readonly="true" />
For layout modifications, this can generally can be overcome by using the "template overrides" approach but that doesn't quite work for a "model override."
This article says you can indeed override a model, but though the use of a custom written plug-in:
http://community.joomla.org/blogs/commu ... -html.html
But, I could not quite understand from the article on how to do that, so I can't give specific help on this part of the procedure.
But, to get back to your original question, changing one word in the models xml profile file or adding one line will do what you want to make the "Name" uneditable.
Marc