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)
By (Deleted User) - June 5, 2010
Hello,
I have a product page and would like to add a number of drop down forms to sort and display only the ones selected.
I have a form like this which does only show the items:
This changes the url to something like: /product-page.php?colour=Red
and does actually only show the red items in the multi-list.
However I would like to do two things.
1. When you say select Yellow and it shows Yellow products, it also keeps Yellow in view on the drop down.
2. Can the items be dynamically added from products with the colour selected? Say if I have 10 items that are blue and 2 red items the drop down list knows there is a least 1 available to show and adds it to the dropdown list - if there are 0 brown items for example, the list doesn't include brown as an option?
Is it also possible to add further drop down lists for the visitor to select things like conditioner, shampoo etc. and brand - what I mean here is, can I add as many drop down list as needed?
Thanks Jono
I have a product page and would like to add a number of drop down forms to sort and display only the ones selected.
I have a form like this which does only show the items:
<form action="/product-page.php"><select name="colour" onchange="this.form.submit();">
<option value="*" selected="selected">Select Colour</option>
<option value="Yellow">Yellow</option>
<option value="Red">Red</option>
<option value="Green">Green</option></select></form>
<form action="/tigi-bedhead.php"><select name="colour" onchange="this.form.submit();">
<option value="*" selected="selected">Select Colour</option>
<option value="Yellow">Yellow</option>
<option value="Red">Red</option>
<option value="Green">Green</option></select></form>
This changes the url to something like: /product-page.php?colour=Red
and does actually only show the red items in the multi-list.
However I would like to do two things.
1. When you say select Yellow and it shows Yellow products, it also keeps Yellow in view on the drop down.
2. Can the items be dynamically added from products with the colour selected? Say if I have 10 items that are blue and 2 red items the drop down list knows there is a least 1 available to show and adds it to the dropdown list - if there are 0 brown items for example, the list doesn't include brown as an option?
Is it also possible to add further drop down lists for the visitor to select things like conditioner, shampoo etc. and brand - what I mean here is, can I add as many drop down list as needed?
Thanks Jono
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:
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:
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.
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
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
Thanks Jono