How can I display multi list from dynamic drop down list

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 6, 2010   (RSS)

Re: [jonoc73] How can I display multi list from dynamic drop down list

By Chris - June 5, 2010

Hi Jono,

Yes, you can add as many drop down lists as you want.

1. This is relatively easy, you'd simply add some PHP code to add a SELECTED attribute if the page request matches the option. We have a function which makes this dirt simple. For example:

<option value="Yellow" <?php selectedIf(@$_REQUEST['colour'], 'Yellow') ?>>Yellow</option>

2. This is a little trickier. You'd need some code to figure out the unique values for a field in a set of records and use that to output the <option>s. Something like this should do the trick:

<select name="colour" onchange="this.form.submit();">
<option value="">Select Colour</option>
<?php echo getSelectOptions(@$_REQUEST['colour'], array_unique(array_pluck($myRecords, 'colour'))) ?>
</select>


However, (and this is a big however,) once someone selects "Red" from the drop down list and searches again, $myRecords will no longer contain any records with colours other than Red, so the drop down list will only have one option! I suppose a way around this would be to do two getRecords() calls, one of them using 'allowSearch'=>false so that it collects all the records.

Please let me know if you have any questions.
All the best,
Chris

Re: [chris] How can I display multi list from dynamic drop down list

By (Deleted User) - June 6, 2010

Option 1 works a treat - I think I'll probably stick to that one for now.

Thanks Jono