Hide options in search

gilesk

Member
Hi Fabrikar

I need for the search not to show options when only a registered user is logged in, but if a Administrator or Super User Logs in all options are visible

Please see image attached

When a registered user logs on - under the Category search dropdown I need Honorary not to display

Kind Regards
Kelly Giles
 

Attachments

  • Capture.JPG
    Capture.JPG
    23 KB · Views: 201
The only way I can think of to do this would be to use a database join, in simple dropdown mode, with the "Eval options" under Advanced. That would mean creating a simple List, which just consists of the PK (primary key) and the option name (Honorary, etc), and adding four rows (or however many options you need).

Depending what the element currently is, like if it's a dropdown, this may mean changing the 'values', if you currently use non-numeric values. So you may have to modify any existing values in existing data (simple SQL commands, I can give you them if you need them), and any "logic" you may have elsewhere that uses those value, like in pre-filters, etc.

That way, you could do something like this in the "Eval options" box. Let's assume the PK value for "Honorary" is 3, and that you have a standard J! viewing access group which contains Admins and Super Admins, and it's ID is 20.

PHP:
if ($opts->value == '3') {
    $this_user = JFactory::getUser();
    $this_groups = $this_user->authorisedLevels();
    if (!in_array(20, $this_groups)) {
        return false;
    }
}

This should remove that option from any usage of that dropdown.

NOTE that it won't just remove it from the filter usage, it'll remove it everywhere, for non-admins. Which may not be what you want?

-- hugh
 
Hi Hugh

I have a question on creating a simple list

Is this to be created in Fabrikar with Elements (if Elements ? what plug-in do I use)

Or Joomla backend Database

Kind Regards
Kelly Giles
 
You never actually answered my question as to what element type it was.

I'm assuming it's currently a 'dropdown', in which you have set up "Labels" and "Values" for your options.

if so, then create a Fabrik list, which will automatically create an 'id' element, which will be the equivalent of the "Value" you were using for a dropdown element. Create a simple field element called something like "name", which will be the equiv of the "Label" from the dropdown.

Now add new rows to this List, using the usual Fabrik way (Add a new Form from the List display), one for each of the options you had on the old dropdown element.

Now create a 'database join' element on your original list (or change the type of the original dropdown element), set it to render as 'dropdown', select your new table, set the 'value' to the 'id' element, and the 'label' to the 'name' element.

You should now have a join element dshowing as a dropdown on your form, which looks and behaves just like the original dropdown element.

Only now, you have the option to do what I described in my previous post, and decide which of the options you want to show.

The only potential gotcha is if you have existing data for the original dropdown. In which case, BEFORE you change the type of the old dropdown element to a join, you'll need to change the existing data to match the new values.

So say in your original dropdown you had a an option with the label "Social", and the value "soc". You'll need to look at your new table, and find out the value of the new 'id' for the 'Social' row, let's say it's 4. Then change all existing saved data for that from 'soc' to '4' in the old field. You'll have to use something like phpMyAdmin to do this, either by editing each existing row by hand, or there are too many to do that, you can change them all in one SQL query:

UPDATE yourtable SET your_dropdown_element = "4" WHERE your_dropdown_element = "soc"

... just change the table and field names to suit.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top