Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to control and disable the first option in dropdown list which is "ALL CATEGORY" when normal user is login. The first option in dropdown list is for admin only.

What I have tried:

<div class="form-group">
		<label class="col-md-3 control-label sbold text-right">Category</label>
			<div class="col-md-3">													
			<select class="form-control select2" name="type">
				<?php
				foreach ($ListType as $key => $value){
					$filter['type'] == $value ? $xSelect = ' selected="selected"' : $xSelect = '';
						echo '<option value="'.$value.'"'.$xSelect.'>'.$value.'</option>';
				}
				?>
			</select>												
			</div>
		</div>



PHP
$ListType = array("ALL CATEGORY", "STAFF", "SUPERVISOR");
Posted
Updated 27-Jun-22 23:44pm
v2

1 solution

To disable an option you can use <option .. disabled> which prevents it from being selected. However what you should probably be doing instead is not displaying the option altogether as it's incredibly easy for anyone with a little HTML knowledge to just remove the disabled attribute from the option through the debugger tools in the browser.

So instead, change your PHP code to check whether the user is an admin and exclude it otherwise. Then, in the part of your PHP code which handles the form submission, make sure to also check there as well to prevent non-admin users from sneakily submitting the value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900