How to Add Drop Down List Field with Values Loaded from the CMS

By Rusty - December 14, 2010

I followed the steps for adding Radio Fields, however modified it a bit, but I'm not exactly what's going on with it. Why is it displaying the value for the drop down list instead of the label. I labeled the fields as suggested: value|label in my case <250cc|250cc or Less.

Is there a way to pull the "250cc or less" into the user submission form?

I followed the steps for adding radio fields.
</tr>
<tr>
<td>Engine Displacement</td>
<td>
<?php $fieldname = 'mc_engine_cc'; ?>
<?php $idCounter = 0; ?>
<select name="<?php echo $fieldname ?>">
<?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<option id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> /><?php echo htmlspecialchars($value) ?></option>
<?php endforeach?>
</select>
</td>
</tr>


This is a portion of the HTML that's rendering a little oddly. Should I NOT use <250cc as an Option Value within the MC_ENGINE_CC field in the CMS?
<tr>
<td>Engine Displacement</td>
<td>
<select name="mc_engine_cc">

<option id="mc_engine_cc.1"
value="&lt;250cc" />&lt;250cc</option>
<option id="mc_engine_cc.2"
value="&lt;500cc" />&lt;500cc</option>
<option id="mc_engine_cc.3"
value="&lt;1000cc" />&lt;1000cc</option>
<option id="mc_engine_cc.4"
value="&gt;1000cc" />&gt;1000cc</option>
</select>
</td>
</tr>

Rusty

Re: [Rusty] How to Add Drop Down List Field with Values Loaded from the CMS

By Jason - December 14, 2010

Hi Rusty,

What's happening is your outputting $value in 2 places instead of using $label in the other. You can also remove the "htmlspecialchars()" function if you don't want display the encoded value (ie < instead of &lt;)

Try this:

<option id="<?php echo $id ?>" value="<?php echo $value ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> /><?php echo $label ?></option>

Hope this helps
---------------------------------------------------
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] How to Add Drop Down List Field with Values Loaded from the CMS

By Rusty - December 14, 2010

Thanks for the rapid response. Sometimes these minor code oversights can be the ones that give you the most trouble. Thanks [sly]
Rusty