QuickForm select element with disabled items

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Chivalry
Forum Newbie
Posts: 2
Joined: Mon May 04, 2009 4:18 pm
Location: Menifee, CA

QuickForm select element with disabled items

Post by Chivalry »

I have code using QuickForm that creates a select widget with the following:

Code: Select all

$form->addElement( 'select', 'state_id', 'State:', statesArray() );
statesArray()queries the database to get the states available and returns an associative array with the ids linked to the state names. I'm using a similar technique throughout the solution.

What I'd like to do is prepend this array with two options that are disabled, so that by default the select menu says something like "Please select a state" followed by a dash, both of which are disabled. If I weren't using QuickForm, the select would have the following as the first two options:

Code: Select all

<option value="" disabled="disabled">Select a State</option>
<option value="" disabled="disabled">-</option>
Both options are disabled, and if the user leaves the option on the first value, the select widget submits an empty value which is made invalid by the form checking code.

Is there a way to do this with QuickForm?

Thanks,
Chuck
Post Reply