WORKING WITH MULTI VALUE CHECK BOXES IN FORMS - Dec 29th, 2015
|
According to Jason Sauchuck, from Interactive Tools, Multi-value checklists and multi-value pull downs are both stored the same way in CMS Builder,
In this example I'm populating the list of possible option values (num) and option labels (text) for the levels_of_care field from another table
Using the basic approach in the website membership plugin's profile update form, and with some help fro Ross Fairbairn, also from Interactive Tools, I was able to populate a multi value check box list field (levels_of_care in this example), and update the list in my table (accounts in this case),use the following code in my form:
<tr> <td valign="top">Levels of Care</td> <td><?php $fieldname = 'levels_of_care'; ?> <?php if(is_array(@$_REQUEST[$fieldname])){ $fieldValues = $_REQUEST[$fieldname]; } else{ $fieldValues = explode("\t",trim(@$_REQUEST[$fieldname],"\t")); } ?> <?php $idCounter = 0; ?> <?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?> <?php $id = "$fieldname." . ++$idCounter; ?> <input type="checkbox" name="<?php echo $fieldname ?>[]" id="<?php echo $id ?>" value="<?php echo htmlspecialchars($value) ?>" <?php if(in_array($value,$fieldValues)):?> checked="checked" <?php endif ?>/> <label for="<?php echo $id ?>"><?php echo htmlspecialchars($label) ?></label> <?php endforeach ?></td> </tr>
And this code in the colsToValues array:
$colsToValues['levels_of_care'] = "\t" . implode("\t", $_REQUEST['levels_of_care']) . "\t";
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.