4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 6   (RSS)

Hello,

I have created a dropdown list in CMSB with different options and the options are pulled from the database.

One of the options is called "Management" and I would like to hide this from the front-end so it only displays for certain types of users. I am using the Website Membership plugin.

Could someone please help me update the code below to achieve this?

<?php
// get field options
$tablename = 'units';
$fieldname = 'unit_name';
$selectedValue = @$_REQUEST['unit_name];
$valuesAndLabels = getListOptions($tablename, $fieldname);
foreach($valuesAndLabels as $key => $val) {
if(!is_numeric($key)) {
unset($valuesAndLabels[$key]);
}
}
$optionsHTML = getSelectOptions($selectedValue, array_keys($valuesAndLabels), array_values($valuesAndLabels));
?>

Thank you,

Greg

Hi Greg,

I think something like the following should do the trick:

<?php
  global $CURRENT_USER;

  // get field options
  $tablename = 'units';
  $fieldname = 'unit_name';
  $selectedValue = @$_REQUEST['unit_name'];
  $valuesAndLabels = getListOptions($tablename, $fieldname);
  foreach($valuesAndLabels as $key => $val) {
    if(!is_numeric($key)) {
      unset($valuesAndLabels[$key]);
    }
    
    if($val == 'Management' && $CURRENT_USER['member_type'] != 'value') {
      unset($valuesAndLabels[$key]);
    }
  }
  $optionsHTML = getSelectOptions($selectedValue, array_keys($valuesAndLabels), array_values($valuesAndLabels));
?>

A few things to note:

  • You only need to add "global $CURRENT_USER;" if it doesn't already appear earlier in the code
  • You'll need to update "$CURRENT_USER['member_type'] != 'value'" to match the field name and value you're using in your members table

Let me know if you have any questions!

Thanks,

Daniel
PHP Programmer
interactivetools.com

Hi Daniel,

That's exactly what I was hoping for, thank you very much!

Regards,

Greg