HTML Forms - Prevent some users checking a checkbox
I have a form that users fill in. According to the level of access they have, I want to prevent some of my form being filled in.
If I have a text box I use this onfocus='blur()'
with a bit of php to check the users privileges开发者_运维知识库 .But this does not work for a checkbox. Can anybody suggest how I can prevent a user from checking a checkbox still having it visible for reference ?
Any help would be much appreciated
Thanks
Give it a disabled
attribute. As you currently do, use PHP to check for the user's privilege, and only add the attribute if the user can't use the checkbox. Updated my example with some pseudo-PHP to illustrate:
<?php if (user can access this field) : ?>
<input type="checkbox" name="some-field" value="some-value" />
<?php else: ?>
<input type="checkbox" name="some-field" value="some-value" disabled="disabled" />
<?php endif; ?>
Try this:
<input type="checkbox" name="mycheckbox" disabled="disabled"> Disabled Option
If you need it to be disabled only for certain users, do something like this:
<input type="checkbox" name="useronly" <?php if(!$useraccessgranted) { echo 'disabled="disabled"'; ?> />
or something to that effect. This should not be hard
精彩评论