Show/Hide Plugin, Show/Hide Dependant Fields

9 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 15, 2013   (RSS)

By Mikey - February 17, 2013 - edited: February 17, 2013

Can someone shed more light on how to get this plugin working?

// For each section and list field, copy this block

...where exactly does this code go? In a list field type and and as what?

Use options listed belowGet options from database
Get options from MYSQL query

Here's my block of code:

$GLOBALS['SHOWHIDE_DEPENDANT_FIELDS_CONFIG']['admissions']['sub_content'] = array(
// list option   => fields to show
  ''             => array(), // show these fields when the topmost '<select>' option is selected
  'simple'       => array(),
  'advanced'     => array( 'sub_title','sub_description','sub_summary'),
  '_any_value_'  => array('sub_title','sub_description'), // show these fields when a value not listed above is selected
);

I've tried everything I can think of, but just can't get this to work.

Also, is the CVS folder required for this plugin?

Thanks,

Zick

By gregThomas - February 18, 2013

Morning, 

I've had a play with Chris's plugin and have got it working, I'll explain how to use it:

//Name of the field in the accounts table you want to use for your 'skill' level. I've used the isAdmin field.
$GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME'] = 'isAdmin';

// For each section, copy this block
$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['section_name1'] = array(
  // is the user an admin (0 for false, 1 for true) and lists of fields to hide in the section_name1 section
  '0' => array('field_1', 'field_2'),
  '1'   => array('field_1')
);

// For each section, copy this block
$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['blog'] = array(
  // is the user an admin (0 for false, 1 for true) and lists of fields to hide in the blog section
  '0' => array('title', 'subject'),
  '1'   => array('')
);

So the BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME variable contains the field in the accounts section that you want to use to decide if a particular user can see fields. In this example I've decided to use the isAdmin checkbox field.

In this example I've decided to hide fields in two different sections; blog and section_name1. In the section_name1 section a user who isn't an admin (so isAdmin would be set to 0) will not be able to see the fields field_1 or field_2. But if they are an admin, they won't be able to see only field_1.

In the blog section, non admin members can't see the title or subject fields. But an admin member would be able to see all fields.

If you wanted to hide fields in another section, you would copy and paste one of the blocks below the other two and modify it required.

Let me know if you want be to clarify anything.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Mikey - February 18, 2013

Thanks for the help Greg. You're explanation helps shed some light on how to use the show hide features, but I'm still unclean where exactly the code goes to even begin to build the show / hide feature. See my bold copy next to your example. And many thanks for the help!!!

Zick

//Name of the field in the accounts table you want to use for your 'skill' level. I've used the isAdmin field.
$GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME'] = 'isAdmin'; Where does this code go? In a list field type? If Yes as what? A (Use options listed below, Get options from database or
Get options from MYSQL query)


// For each section, copy this block Where does this code go? In a list field type? If Yes as what? A (Use options listed below, Get options from database or
Get options from MYSQL query)

$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['section_name1'] = array(
  // is the user an admin (0 for false, 1 for true) and lists of fields to hide in the section_name1 section
  '0' => array('field_1', 'field_2'),
  '1'   => array('field_1')
);

// For each section, copy this block Where does this code go? In a list field type? If Yes as what? A (Use options listed below, Get options from database or
Get options from MYSQL query)
$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['blog'] = array(
  // is the user an admin (0 for false, 1 for true) and lists of fields to hide in the blog section
  '0' => array('title', 'subject'),
  '1'   => array('')
);

By gregThomas - February 19, 2013

Hi Zick, 

This code just needs modifying in the plugin, you don't need to copy or add it anywhere. You should find it on lines 15 to 30 of showHideFieldsForUsers.php in the cmsAdmin/plugins/ directory.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Mikey - February 26, 2013

Thanks for clearing things up Greg... I've got it up and running. Really nice add-on.

Cheers.

By Codee - May 15, 2013

Hi Greg,

Thank you kindly for clearing this up quite a bit more. How would we code this if we want to show/not show parts of the section to several different user levels? Let's say we have 6 user levels: admin, alpha, beta, kappa, omega, and zeta.  And we want admin to see all, alpha to only see "subject", beta to see "subject", "description", "timeline".  The rest see what beta does plus "price", "testimonial", and "delivery_instructions". ?  Thanks!

By gregThomas - May 15, 2013

Hi,

You would need to add a row for each user type that you want to hide fields for, something like this would work:

$GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME'] = 'user_levels';

// For each section, copy this block Where does this code go? In a list field type? If Yes as what? A (Use options listed below, Get options from database or
Get options from MYSQL query)
$GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['section_name_goes_here'] = array(
  // is the user an admin (0 for false, 1 for true) and lists of fields to hide in the blog section
  'alpha' => array('description','price','timeline','testimonial','delivery_instructions'),
  'beta' => array('price','testimonial','delivery_instructions'),
  'kappa' => array('price','testimonial','delivery_instructions'),
  'omega' => array('price','testimonial','delivery_instructions'),
);

This is just example code, so you'll need to make a few changes to get it working with your site. You'll need to add the section name that this is applicable to $GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG'], and add the field name in the user section to $GLOBALS['BETA_USER_SKILL_FIELDS_SKILL_FIELD_NAME'].

So for each possible option in user_levels I've added an entry to the $GLOBALS['BETA_USER_SKILL_FIELDS_CONFIG']['section_name_goes_here'] array. Then I've added the fields that I don't want that user to be able to edit to that users array.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Codee - May 15, 2013

Excellent! Thanks Greg!