We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45118
    • 123 Posts
    I'm trying to make these checkboxes sticky by adding a placeholder in the html and using this in the snippet:
    $checked = 'checked="checked"';
    $modx->setPlaceholder($group . '_checked', $checked);
    This method works for me with radios but not with the checkboxes.
    Here's the complete code
    Form:
    <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>


    And snippet:
    <?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;

    Any help is greatly appreciated!

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      Line 26 is only setting one placeholder. I think it needs to go inside the foreach loop.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 45118
        • 123 Posts
        Quote from: BobRay at Oct 23, 2015, 04:22 PM
        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!! smiley I only had to change $group into $selected.
        Here's the changed snippet:
        $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;
        Thanks so much!!
        • discuss.answer
          • 3749
          • 24,544 Posts
          I'm glad I could help. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting