$checked = 'checked="checked"'; $modx->setPlaceholder($group . '_checked', $checked);
<div>[[+total]] Products</div> <form action="[[~[[*id]]]]" method="POST"> <p>Choose a Group or Groups:</p> <div id="check"> <input type="checkbox" name="group[]" value="BRA" [[+BRA_checked]] id="check1" /> <label for="check1">Brackets</label> <input type="checkbox" name="group[]" value="BLK" [[+BLK_checked]] id="check2" /> <label for="check2">Blocks</label> <input type="checkbox" name="group[]" value="COR" [[+COR_checked]] id="check3" /> <label for="check3">Corbels</label> <input type="checkbox" name="group[]" value="GBR" [[+GBR_checked]] id="check4" /> <label for="check4">Gingerbreads</label> <input type="submit" name="group[]" Value="Submit"/> </div> </form>
<?php
$output = "";
$path = MODX_CORE_PATH . 'components/aeibbproducts/';
$result = $modx->addPackage('aeibbproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$group = array();
if (isset($_POST['group']) && (! empty($_POST['group']))) {
$group = $_POST['group'];
}
$c = $modx->newQuery('BbProducts');
$where = array();
foreach($group as $selected) {
$where[] = array('pre' => $selected);
}
$c->where($where, xPDOQuery::SQL_OR);
$checked = 'checked="checked"';
$modx->setPlaceholder($group . '_checked', $checked);
$total = $modx->getCount('BbProducts',$c);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$modx->setPlaceholder($totalVar,$total);
$modx->runSnippet('FeetInch');
$fi = new FeetInch($modx);
$noImage ='assets/media/jpgs/noimage-s.jpg';
$products = $modx->getCollection('BbProducts',$c);
foreach($products as $product) {
$fields = $product->toArray();
$width = $product->get('width');
$fields['nwW'] = 'Width: ' . $fi->dec2inch($width);
$height = $product->get('height');
$fields['nwH'] = 'Height: ' . $fi->dec2inch($height);
$proj = $product->get('proj');
$fields['nwP'] = 'Proj: ' . $fi->dec2inch($proj);
$pitch = $product->get('pitch');
$fields['nwPi'] = $pitch . ' Pitch';
$fleName = $product->get('aei');
$temp = 'assets/media/jpgs/prod-s/' . '01-' . $fleName . '.jpg';
$fields['imgLink'] = file_exists($temp) ? $temp : $noImage;
$output .= $modx->getChunk('showBrackets', $fields);
}
return $output;This question has been answered by multiple community members. See the first response.
Line 26 is only setting one placeholder. I think it needs to go inside the foreach loop.Hi Bob, I tried that and it worked!!
I only had to change $group into $selected.$output = "";
$path = MODX_CORE_PATH . 'components/aeibbproducts/';
$result = $modx->addPackage('aeibbproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$group = array();
if (isset($_POST['group']) && (! empty($_POST['group']))) {
$group = $_POST['group'];
}
$c = $modx->newQuery('BbProducts');
$where = array();
$checked = 'checked="checked"';
foreach($group as $selected) {
$where[] = array('pre' => $selected);
$modx->setPlaceholder($selected . '_checked', $checked);
}
$c->where($where, xPDOQuery::SQL_OR);
$total = $modx->getCount('BbProducts',$c);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$modx->setPlaceholder($totalVar,$total);
$modx->runSnippet('FeetInch');
$fi = new FeetInch($modx);
$noImage ='assets/media/jpgs/noimage-s.jpg';
$products = $modx->getCollection('BbProducts',$c);
foreach($products as $product) {
$fields = $product->toArray();
$width = $product->get('width');
$fields['nwW'] = 'Width: ' . $fi->dec2inch($width);
$height = $product->get('height');
$fields['nwH'] = 'Height: ' . $fi->dec2inch($height);
$proj = $product->get('proj');
$fields['nwP'] = 'Proj: ' . $fi->dec2inch($proj);
$pitch = $product->get('pitch');
$fields['nwPi'] = $pitch . ' Pitch';
$fleName = $product->get('aei');
$temp = 'assets/media/jpgs/prod-s/' . '01-' . $fleName . '.jpg';
$fields['imgLink'] = file_exists($temp) ? $temp : $noImage;
$output .= $modx->getChunk('showBrackets', $fields);
}
return $output;