Options in a form populated only from checked values in a field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 23, 2013   (RSS)

By gkornbluth - July 23, 2013

Hi All,

I’m trying to set up a form field on a detail page paypal form that will allow a buyer to choose the color of an item from only those colors available for that particular item.

The colors available are in a multi-value check box in the item's record. (Possible values are from another database using the "record number" for the value and a" title" field value for the label)

Right now I’m using the following code, and it lists all available colors in the form, whether checked as available or not.

I've mucked about but can’t seem to figure out how to list only the colors that are checked as available in the particular record.

<select name = "os1" >
<option value="">Please Choose a Color</option>
<?php foreach (getListOptions('store_inventory', 'colors') as $value => $label): ?>

<option value = "<?php echo $label;?>" <?php selectedIf($value, @$_REQUEST['colors']);?>>

<?php echo $label; ?></option>

<?php endforeach ?>

</select>

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - July 23, 2013

Hi Greg,

Thanks for your suggestions. The page works perfectly now and I've created a recipe in my CMSB Cookbook so that others can learn from the master (that's you).

The final code for selecting available colors in the PayPal "Buy Now" button ended up being:

<input type="hidden" name="on1" value="Color">
                        
   <?php  // load record from 'store_inventory'
  list($colors, $store_inventoryMetaData) = getRecords(array(
    'tableName'   => 'store_inventory',
    'where'       => whereRecordNumberInUrl(1),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
   ?>                    
  <?php $available_colors = $colors['0'];

  //Create a drop down list by combining the values and labels into one array
  $dropList = array_combine($available_colors['colors:values'], $available_colors['colors:labels']);

  ?>
  <select name="os1">
    <option value="">Please Choose a Color</option>
    <!-- cycle through drop list to create options -->
    <?php foreach($dropList as $value => $label): ?>
      <option value = " <?php echo $label; ?>" <?php selectedIf($value, @$_REQUEST['colors']);?>> <?php echo $label; ?></option>
    <?php endforeach; ?>
  </select>

We certainly couldn't accomplish what we do without your expert guidance.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php