I'm trying to figure out how to add a disabled option in my dropdown, using codeIgniter. New to CI, and I've tried googling it a bit, but couldn't find an answer.
My code for a dropdown looks like this:
echo form_dropdown('category', array('0' => 'Choose a category...') + $categories, '0');
This gives me a dropdown with all my options from the variable $categories, with "Choose a category..." (value 0) at top. Now how to I make the first one disabled? I know how to make it select a specific one, which I've set it to do here.
Can anyone help me? Thanks
I know this is an old post, but in the current version of CI, I can do a little (sql-injection-like) trick by appending " disabled="disabled
to the keys of the option I would like to disable.
$categories['0'] = '(Select Category)';
$categories['1'] = 'Category 1';
$categories['2" disabled="disabled'] = 'Restricted Category';
$categories['3'] = 'Category 3';
echo form_dropdown('category', $categories, '0');
I am not sure if this is a bug of CI's form_helper, since it does not do any escaping or sanitizing function for the dropdown key/values. For the mean time, to be safe, just make sure your keys and values wont be coming from any user-based input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With