drop down list

7 posts by 3 authors in: Forums > CMS Builder
Last Post: May 21, 2012   (RSS)

By Joef5 - May 17, 2012

I have a products section where I can add product name, product id, description, price, shipping, etc. Some products are identical except for one feature - such as flavor or size.
How can I create a drop down list specific to each product, so that on the public pages, the viewer sees the list of options?
So for a product like milk shakes - the options would be vanilla, chocolate, strawberry, but for a product like Tee Shirts, the option might be for red, blue, green? Very few of the products would have the same list of options.

Re: [Joef5] drop down list

By Jason - May 18, 2012

Hi,

To do this, for any given product, you would need to know which field contains it's list of options. You could have a drop down called "optionsField" where you would select from a list of different field names. You could then use that value to select option values for that product.

For example:

<select name = "option">
<?php foreach ($record[$record['optionField'].":values"] as $value): ?>
<option value = "<?php echo $value;?>"><?php echo $value;?></option>
<?php endforeach ?>
</select>


In this example, we assume a few things:
1) optionField has a value that is the name of another field in your record
2) that other field is a multi value list (drop down or checkboxes)

Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] drop down list

By Joef5 - May 18, 2012 - edited: May 18, 2012


So it is the second part where I run into the difficulty.
The field that is the multi value list - how is that set up in the
section editor? When I look at the list option, it seems the list then applies to all the products, not one specific record.
I want to be able to create the drop down list as shown in your code snippet, but have each item with a unique set of choices in the drop down list.

I added a text field called options.
Entered data in the field - vanilla,chocolate,strawberry

included the code below:

<?php foreach ($productsRecords as $record): ?>
<table cellpadding="3" cellspacing="0" border="0" width="100%"><tr><td align="left" valign="top" class="just">


<h1><?php echo $record['Name'] ?></h1>

Price: <?php if ($CURRENT_USER): echo "$".$record['Price'] ; endif ?><?php if (!$CURRENT_USER): echo "<a href='http://website.com/login.php'>Login to see price.</a>"; endif ?><br/>
Product ID: <?php echo $record['Product_id_sku'] ?><br/>
<select name = "option">
<?php foreach ($record[$record['options'].":values"] as $value): ?>
<option value = "<?php echo $value;?>"><?php echo $value;?></option>
<?php endforeach ?>
</select>
<?php echo $record['Summary'] ?><br/>
<?php echo $record['options'] ?>
<br/>
<a href="<?php echo $record['_link'] ?>">Click for More Details</a><br/>


The options are shown as entered where the echo statement is.
The drop down box is not populated, just blank, no options.

Joe

Re: [Joef5] drop down list

By robin - May 18, 2012

Hey Joe,

You can setup a multi value list in the section editor. For your "options" field - go into the modify popup and choose the " checkboxes (multi value)" option under "Display As".

That will make change the list options to be checkboxes in the product editor and you can choose which options will be available for each product.

Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] drop down list

By Joef5 - May 18, 2012

Thanks Robin,

So doing as you said, then going into the product editor, the check boxes are there, displays the information, checked the boxes - but no show on the public display pages.

If I include <?php echo $record['options'] ?> it will output all the items that are checked in the product editor.

It appears this section of code is not returning any values or records.

<select name = "options">
<?php foreach ($record[$record['options'].":values"] as $value): ?>
<option value = "<?php echo $value;?>"><?php echo $value;?></option>
<?php endforeach ?>
</select>

--
Any thoughts on why it is not displaying the records?

Thanks,

Joe

Re: [robin] drop down list

By Joef5 - May 21, 2012

Thanks Robin,

That Works!