Hide option from select menu with PHP

4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 6, 2020   (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 Daniel,

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

Regards,

Greg

By mbareara - January 6, 2020

this is the code

<?php 
  list($localiRecords, $localiMetaData) = getRecords(array( 
    'tableName' => 'locali',  
    'limit' => '4', 
    'where' => mysql_escapef('city = ? AND num != ?', $localiRecord['city']),
  ));
?>
				<?php foreach ($localiRecords as $record): ?>