Keyword

Hiding unwanted fields in frontend editor by user group

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 4 months ago #93349 by Terry Britton
I have seen several posts regarding hiding unwanted fields in the frontend editor and several posts asking about getting the user's group, and I needed to do both, so here's my solution.

Put the following code near the top of form.php

<?php// get user ID$user = &JFactory::getUser();$userId = $user->get('id');// get user Group$db =& JFactory::getDBO();$query = "  SELECT ".$db->nameQuote('group')."    FROM ".$db->nameQuote('jos_k2_users')."    WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId).";  ";$db->setQuery($query);$userGroup = $db->loadResult();?>

 

You can then surround whatever element you want to hide as in the following example where I hide the toggle sidebar unless user is editor or site owner.

 

<?php if($userGroup == 2 OR $userGroup == 4) : ?>    <div id="k2ToggleSidebarContainer">     <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a>    </div>   <?php endif; ?>

 

These are my user group numbers and will be different on your site. Just check your database (jos_k2_user_groups) to get the numbers that correspond to each of your groups. 

Please Log in or Create an account to join the conversation.

More
14 years 4 months ago #93350 by william white
No rating system here so i will make one *****

This can be used in many instances, especially the query of the database to get info

thanks for posting!

Please Log in or Create an account to join the conversation.

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 4 months ago #93351 by Terry Britton
William,

Here's a great resource for writing db queries in Joomla: docs.joomla.org/How_to_use_the_database_classes_in_your_script.William White said:

No rating system here so i will make one *****

This can be used in many instances, especially the query of the database to get info

thanks for posting!

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #93352 by Radik
Where is file form.php? I can;t find it. Please help me!

Please Log in or Create an account to join the conversation.

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 months ago #93353 by Terry Britton
/components/com_k2/views/item/tmpl/form.php

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #93354 by Radik
I have extra fields, Can i hide this fileds?

Please Log in or Create an account to join the conversation.

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 months ago #93355 by Terry Britton
In the input form or in the item view?

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #93356 by Radik
I need to hide Extra fields from non-registered users. If a user is logged in Extra Fields need to show.

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #93357 by Radik
Can You help me?

Please Log in or Create an account to join the conversation.

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 months ago #93358 by Terry Britton
In item.php add the following near the top of the page.

<?php$user = &JFactory::getUser();$userId = $user->get('id');?>

Then surround the extra fields (lines 254-268) with the following.

<?php if($userId != 0) : ?>

    extra fields stuff

<?php endif; ?>

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #93359 by Radik
Thank You very much!

Please Log in or Create an account to join the conversation.

More
13 years 11 months ago #93360 by Mihir Patel
Hello Terry, 

Can you tell me how to hide the extrafields from the form.php.......I tried it but not successful. I want two user type in jomsocial. I just want to hide the last extrafield for one of the two user types.

 

Below is the code in form.php. anything i am trying to echo in td...its not even displaying....Am i working on wrong page or wat ???

 

<table class="admintable" id="extraFields" >

<?php foreach ($this->extraFields as $extraField): ?>

<tr>

<td align="right" class="key"><?php echo $extraField->name; ?></td>

<td><?php echo $extraField->element; ?></td>

</tr>

<?php endforeach; ?>

</table>

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago - 11 years 6 months ago #93361 by Alessandro Catania
Replied by Alessandro Catania on topic Re: Hiding unwanted fields in frontend editor by user group
Hi, I discovered this topic from 3 years ago. I need to hide some things but the code write here isn't understandable for me that don't know php. I try to re-write the code, but this doesn't work for me. Can anybody correct it?

PS: the file is now at components/com_k2/templates/default/itemform.php i think. send me your feedback
<?php get user ID$user = &amp;JFactory::getUser();$userId = $user->get('id'); get user Group$db =&amp; JFactory::getDBO();$query = "  SELECT ".$db->nameQuote('group')."    FROM ".$db->nameQuote('jos_k2_users')."    WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId).";  ";$db->setQuery($query);$userGroup = $db->loadResult();?>
<?php if($userGroup == 2 OR $userGroup == 4) : ?>    <div id="k2ToggleSidebarContainer">     <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a>    </div>   <?php endif; ?>

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum