• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Add a field that only Joomla superuser can edit?

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43518

Does anyone have any ideas as to how I can add a field that only a Joomla superuser or special user can view or edit? I want to add a dropdown field so that as forms are submitted, an administrator can review the form data and Accept, Deny or mark Pending on the form. I understand that there's no particular functionality on individually assigning fields permissions based on User Groups. But, I was hoping someone may have an idea as to how I can get the same result. Thanks
The administrator has disabled public write access.

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43521

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

The simplest solution for this scenario would be to add a hidden field to your form that has the default value set to "Pending", then use the "Submissions Directory" menu item to allow only super administrator level users to edit the submissions and change the value of this hidden field.

Another option would be to add a dropdown field to your form with the three statuses and use a custom script in "Scripts called on form display" that will check the user group the current user submitting the form belongs to and either show or hide this field in the front-end.

A third and more complex solution would be to use two forms, one for the initial submission and one for the review. The review form should be able to view the information submitted in the first form and provide super administrator users the field for setting the status. You will require custom scripting in order to link the two forms and also pay close attention to the requirements of your scenario, for example if you want to display this status to the submitting users, but not allow them to edit this at all.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43522

Thank you! I will try options 1 and 2, I don't know if I can figure out the coding for 2, but I'll try to figure it out. Great ideas! Thanks
The administrator has disabled public write access.

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43525

Thanks. The first option won't work well for me because the administrative user would be free-hand typing the status too many times in a regular text box and risk bad data. And unfortunately, I don't know basic php, so I am not able to code the second option offered. It's too bad that rsforms does not offer settings on the front end to facilitate basic forms work-flow.

In any case, the example links that were given to me in my tech support ticket were helpful. Although it is not an ideal solution, I learned by looking through many examples that I can have a dropdown field with my three options, and just include style="display:none;" in the Additional Attributes section of the dropdown field, in order for the field to not be displayed to regular users completing the form. Then make the field viewable/editable in the Submissions Directory listing. So this solution will work fine.

Ideally, I would really appreciate it if anyone who knows php could show me the lines of code it would take to

1. Hide my dropdown field on form display
2.Check if the logged in username is = to a hardcoded constant (say "JohnDoe")
If username == "JohnDoe"
3. Show my dropdown field
{ show ; }

Thanks.
The administrator has disabled public write access.

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43526

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

Although not an exact example for the username, the following code snippet will show a different message based on the logged in user group:
$user = Joomla\CMS\Factory::getUser();
$groups = $user->get('groups');
$specificGroup = 8; //this is the id of the Super Administrator Group
if(in_array($specificGroup, $groups)) {
echo "User is in the Super Administrator Group";
} else {
echo "User is not in the Super Administrator Group";
}

You can adjust this script to take into account the username of the logged in user with:
$user = Joomla\CMS\Factory::getUser();
if($user->get('username') == 'JohnDoe' ) {
echo "Username is JohnDoe";
} else {
echo "Username is not JohnDoe";
}

In order to show or hide a field based on the user group or username you will need to add an unique string to the container of the dropdown field, you can do so by editing the "Form layout" HTML code, then in PHP Scripts > Scripts called on form display use the $formLayout variable and the PHP function str_replace() to replace that unique string with either style="display:none;" or an empty value to remove it. This way if the correct user group or username is used the unique string is replaced with a blank value and the field is shown, otherwise it will be hidden with the style="display:none;" CSS rule.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Add a field that only Joomla superuser can edit? 10 months 2 weeks ago #43532

ok. I see. Thank you so much. I'll definitely try it.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!