Populating a dropdown menu via CMSB

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 19, 2011   (RSS)

I have a form on a client's site that is hand-coded - http://www.mdldoors.com/contact-order.php. There's a section near the top labelled "Store".

The rest of the site has some sections that are updated via CMSB. Is it possible to set up this drop-down menu so the client can update it with CMSB?

Thanks!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Populating a dropdown menu via CMSB

By Jason - August 19, 2011

Hi,

Sure, if you set up a section in the CMS to store a list of store names, you can use that list to dynamically populate a select box.

In this example, we're assuming that the section is called "stores".

First we select all the stores from the database. We also select which fields we want to use as the options values and labels. in this example, we use "num" and "title", but these can be changed to whatever you want:


<?php

$query = "SELECT * FROM `{$TABLE_PREFIX}stores`";
$stores = mysql_query_fetch_all_assoc($query);

$valueField = "num";
$labelField = "title";
?>


Then we output your select box:

<select id="Store Name" class="select480" name="Store Name">
<option value = "">Please Select...</option>

<?php foreach ($stores as $store): ?>
<option value = "<?php echo $store[$valueField];?>" <?php selectedIf($store[$valueField], @$_REQUEST['Store Name']);?>><?php echo $store[$labelField];?></option>
<?php endforeach ?>

</select>


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] Populating a dropdown menu via CMSB

Thanks for your reply, Jason.

This page uses a form to email script - http://www.snaphost.com/captcha/ - so will using your method enable me to show the user's choice as a selected field in the resulting email?

Cheers,
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Populating a dropdown menu via CMSB

By Jason - August 19, 2011

Hi Nigel,

Everything should work the same, the only difference is how the select box is populated. If you're just sending the value of the field in an email, you may not want to use "num" as the value field, consider a text based field like "title" instead.

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/