How do you auto-populate a select drop down with custom field data?
Is there a way to auto-populate a select drop-down menu from custom field data in a low search form? Similar to how you would do this:
<select name="search:genre">
<option value="" {if genre ==""}selected="selected"{/if}>All Genres</option>
{option:genre}
<option value="{option_value}" {selected}>{option_name}</option>
{/option:genre}
</select>
Replies
Low 11 May 2012 11:00
The options for a select drop-down are stored in the DB but in an encrypted manner. This means you'll have to hard-code the options in your template, I'm afraid.
Low 11 May 2012 14:31
I've created a quick plugin to achieve what you want: Low Options.
Tim Alford 11 May 2012 14:55
Thanks for the fast response. Tried it but getting this error:
Error
The following tag cannot be processed:
{exp:low_options:genre}
Please check that the ‘low_options’ module is installed and that ‘genre’ is an available method of the module
Checked and the plugin is installed. "Genre" is also the custom field short name.
Here is the code:
Low 11 May 2012 14:57
Ah, the plugin currently only works with EE2.5... I'll see if I can update it to work with older EE versions, too.
Low 11 May 2012 15:10
Could you try again? You'll need to change the syntax to:
And if you're using it inside the Low Search form, you'll need these conditionals:
Tim Alford 11 May 2012 15:36
Works great for the select EE's default "Select Dropdown" custom field type. Hopefully this is not too much to ask but is there any way it can also work for P&T Multiselect?

Getting these errors on that one:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: libraries/Template.php
Line Number: 3653
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: libraries/Template.php
Line Number: 3726
Probably because of the use of optgroups:
Genre
Sub-Genre
Sub-Genre
Looks like the optigroup comes in as "Array". All others genres list though.
Maybe we should just hard code this.
Low 11 May 2012 15:43
Ah right, optgroups aren't supported now. I'll take a look.
Low 14 May 2012 12:48
Can you try the version that's up in GitHub now? Take note of the slightly different syntax to accommodate for optgroups.
Tim Alford 14 May 2012 14:46
Works like magic. Thank you.