Hide option from select menu with PHP

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

By daniel - December 10, 2019

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
Technical Lead
interactivetools.com

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): ?>