It would be great to have this built-in, in the meantime you can accomplish it using a filter.
Add a drop down to your form but delete all but one of the options then save your form taking note of the form and field id's.
Next open up your themes functions file and paste in the following not forgetting to update the form and field ids to match the ones from your form and drop down. You will also want to edit the option values and labels (on line 5) and add in as many options and optgroups as you require.
add_filter('gform_field_content', 'modify_field', 10, 5);
function modify_field($modify_html, $field){
if($field['formId'] == 11){
if($field['id'] == 5){$modify_html = str_replace("<option value='First Choice' >First Choice</option>",
"<option value='' ></option><optgroup label='Swedish Cars'><option value='volvo'>Volvo</option><option value='saab'>Saab</option></optgroup><optgroup label='German Cars'><option value='vw'>VW</option><option value='audi'>Audi</option></optgroup>",$modify_html);}
}
return $modify_html;
}
Posted 12 years ago on Saturday February 11, 2012 |
Permalink