Prevent users changing "Name" in "Edit Your Profile"

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

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.
Locked
redpizza
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Sep 10, 2011 10:16 pm

Prevent users changing "Name" in "Edit Your Profile"

Post by redpizza » Sat Sep 10, 2011 11:08 pm

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.

RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by RedEye » Sat Sep 10, 2011 11:18 pm

/components/com_user/views/profile/tmpl/edit.php
edit this file or create an override in your template

User avatar
jmuehleisen
Joomla! Virtuoso
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"

Post by jmuehleisen » Sun Sep 11, 2011 5:05 am

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."

Code: Select all

34  <?php foreach ($fields as $field):// Iterate through the fields in the set and display them.?>
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:

Code: Select all

/components/com_users/models/forms/profile.xml
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:"

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"
/>
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:

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"
/>
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

Code: Select all

readonly="true"
to the file, like this:

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"
/>
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.
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials:  http://welcometojoomla.com

redpizza
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Sep 10, 2011 10:16 pm

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by redpizza » Sun Sep 11, 2011 10:51 am

Thanks for your prompt and detailed replies!

User avatar
Sudhir_Dixit
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Aug 13, 2010 8:24 am

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by Sudhir_Dixit » Thu Sep 22, 2011 4:35 am

Hi, jmuehleisen....

You saved me.....thanks for the detailed information...

thanks once again :p

awaisahmad13
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Tue Oct 25, 2011 8:31 am

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by awaisahmad13 » Sat Dec 03, 2011 4:40 am

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.

User avatar
jmuehleisen
Joomla! Virtuoso
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"

Post by jmuehleisen » Sat Dec 03, 2011 4:58 am

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:

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"
/>

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.
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials:  http://welcometojoomla.com

awaisahmad13
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Tue Oct 25, 2011 8:31 am

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by awaisahmad13 » Sat Dec 03, 2011 5:33 am

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.

User avatar
jmuehleisen
Joomla! Virtuoso
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"

Post by jmuehleisen » Sat Dec 03, 2011 7:18 am

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
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials:  http://welcometojoomla.com

beaudoiin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Jan 30, 2015 6:01 am

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by beaudoiin » Sat Jan 31, 2015 3:32 pm

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?

mbressman
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Thu Jun 03, 2010 7:08 pm

Re: Prevent users changing "Name" in "Edit Your Profile"

Post by mbressman » Tue Apr 05, 2016 2:14 am

jmuehleisen 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."

Code: Select all

34  <?php foreach ($fields as $field):// Iterate through the fields in the set and display them.?>
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:

Code: Select all

/components/com_users/models/forms/profile.xml
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:"

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"
/>
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:

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"
/>
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

Code: Select all

readonly="true"
to the file, like this:

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"
/>
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.
This extension will help accomplish this: http://extensions.joomla.org/extension/ ... l-override
Marc


Locked

Return to “General Questions/New to Joomla! 2.5”