<![CDATA[ Fill &tvFilters with selection on front-end to filter - My Forums]]> https://forums.modx.com/thread/?thread=104793 <![CDATA[Fill &tvFilters with selection on front-end to filter]]> https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563542
I have made a filterpage at the frond-end of a website with several listboxes.
The inputs have to be inserted in &tvFilters of GetResources and filter with AND.

But how do i filter if placeholder is empty ?

my form :

<form class="simplesearch-search-form d-flex ruimte-onder" action="[[~34]]" method="POST">
    <div class="col-lg-3 afb-afst">
        <select class="form-control geenradius" type="text" name="optiearch" id="optiearch"  />
            <option value="" disabled selected>Kies architect</option>
            [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`architect` &name=`optiearch`]]
        </select>
    </div>
    <div class="col-lg-3 afb-afst">
        <select class="form-control geenradius" type="text" name="optiewoning" id="optiewoning"  />
            <option value="" disabled selected>Kies type woning</option>
            [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`type-woning` &name=`optiewoning`]]
        </select>
    </div>
    <div class="col-lg-2"><input class="inlog btn geenradius knopbreedte" type="submit" value="Zoekfilter"></div>
    [[!GetZoekFilters]]
</form>


my snippet where i set the placeholders , here i want to add more tv's and make a commaseparated list witch i can use in &tvFilters, but how do i test if the are empty and make the commaseparated list :

<?php
$modx->setPlaceholder('archfilter', $_POST['optiearch']);
$modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);


my filter :

<div class="row">
[[!getPage:default=`[[$gerealiseerd-ovz-leeg]]`?
    &elementClass=`modSnippet`
    &element=`getResources`
    &parents=`[[GetKidsGerealiseerd]]`
    &tpl=`gerealiseerdRowTpl-zoek`
    &sortby=`{[[+idx]]:"ASC"}`
    &showHidden=`1`
    &limit=`8`
    &pageLimit=`5`
    &pageNavVar=`page.nav`
    &depth=`1`
    &includeTVs=`1`
    &processTVs=`1`
    &tvPrefix=``
    &tvFilters=`????`
    &pageFirstTpl=`<li><a[[+classes]][[+title]] href="[[+href]]">Eerste</a></li>`
    &pageLastTpl=`<li><a[[+classes]][[+title]] href="[[+href]]">Laatste</a></li>`
]]
</div>
<div class="clearfix"></div>
<div class="paginas">[[!+page.nav]]</div>


It works when there is no empty listbox value, but not when one is empty.

can someone help me, I'am from the netherlands, so don't mind mistakes in language.

Appeltje]]>
appeltje Jan 11, 2019, 08:57 PM https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563542
<![CDATA[Re: Fill &tvFilters with selection on front-end to filter]]> https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563599
]]>
BobRay Jan 16, 2019, 03:24 AM https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563599
<![CDATA[Re: Fill &tvFilters with selection on front-end to filter]]> https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563568 Quote from: appeltje at Jan 14, 2019, 08:03 PM
Quote from: BobRay at Jan 14, 2019, 07:10 PM
I'm not sure I understand what you're doing, but maybe this will help. It will prevent PHP errors when the $_POST values are not set and allow you to set a default value for them when they are missing or empty:

$archFilter = $modx->getOption('archfilter', $_POST, 'archfilter default value', true);
$typeWoningFilter = $modx->getOption('typewoningfilter', $_POST, 'typewoningfilter default value', true);

$modx->setPlaceholder('archfilter', $archFilter);
$modx->setPlaceholder('typewoningfilter', $typeWoningFilter);

Hi Bob,

thanks for your replay, i have tried your code but still can't get array.

I have tried it in a different way, see my code. don't know if it is the right one, but it works.

<form class="simplesearch-search-form d-flex ruimte-onder" action="[[~34]]" method="POST">
    <div class="row">
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiearch" id="optiearch">
                <option value="" disabled="" selected="">Kies architect</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`architect` &name=`optiearch`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiewoning" id="optiewoning">
                <option value="" disabled="" selected="">Kies woning</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`type-woning` &name=`optiewoning`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optieplaats" id="optieplaats">
                <option value="" disabled="" selected="">Kies plaats</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`plaats` &name=`optieplaats`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optieaann" id="optieaann">
                <option value="" disabled="" selected="">Kies aannemer</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`aannemer` &name=`optieaann`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiekame" id="optiekame">
                <option value="" disabled="" selected="">Kies kamers</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`kamers` &name=`optiekame`]]
            </select>
        </div>
        <div class="col-lg-2"><input class="inlog btn geenradius knopbreedte" type="submit" value="Zoekfilter"></div>
        [[!SetZoekFilters]]
    </div>
</form>


then the next to set de placeholders :

<!--?php
$modx--->setPlaceholder('archfilter', $_POST['optiearch']);
$modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);
$modx->setPlaceholder('plaatsfilter', $_POST['optieplaats']);
$modx->setPlaceholder('aannemerfilter', $_POST['optieaann']);
$modx->setPlaceholder('kamersfilter', $_POST['optiekame']);


then the snippet to make filter array, to put in GetPage &tvFilters :

<!--?php
$arch = $modx--->getPlaceholder('archfilter');
$type = $modx->getPlaceholder('typewoningfilter');
$plaa = $modx->getPlaceholder('plaatsfilter');
$aann = $modx->getPlaceholder('aannemerfilter');
$kame = $modx->getPlaceholder('kamersfilter');

    if(empty($arch)) {
        $arch == NULL;
    }
    else {
        $arch = "architect==" . $arch;  
    }
    
    if(empty($type)) {
        $type == NULL;
    }
    else {
        $type = "type-woning==" . $type;  
    }
    
    if(empty($plaa)) {
        $plaa == NULL;
    }
    else {
        $plaa = "plaats==" . $plaa;  
    }
    
    if(empty($aann)) {
        $aann == NULL;
    }
    else {
        $aann = "aannemer==" . $aann;  
    }
    
    if(empty($kame)) {
        $kame == NULL;
    }
    else {
        $kame = "kamers==" . $kame;  
    }
    
$myfilter = array ("$arch","$type","$plaa","$aann","$kame");
$comma_separated = implode(",", array_filter($myfilter));

echo $comma_separated;


This is wath is working at the moment, please feel free to correct me if the code could be faster or better.
Thanks for your replay.

Greetings Appeltje

Hi Bob,

This is what in the end did the trick, i hope this is well codded.

<?php
$modx->setPlaceholder('archfilter', $_POST['optiearch']);
$modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);
$modx->setPlaceholder('plaatsfilter', $_POST['optieplaats']);
$modx->setPlaceholder('aannemerfilter', $_POST['optieaann']);
$modx->setPlaceholder('kamersfilter', $_POST['optiekame']);

$archfilter = $modx->getPlaceholder('archfilter');
$typewoningfilter = $modx->getPlaceholder('typewoningfilter');
$plaatsfilter = $modx->getPlaceholder('plaatsfilter');
$aannemerfilter = $modx->getPlaceholder('aannemerfilter');
$kamersfilter = $modx->getPlaceholder('kamersfilter');

    if(empty($archfilter)) {
        $archfilter == NULL;
    }
    else {
        $archfilter = "architect==" . $archfilter;  
    }
    
    if(empty($typewoningfilter)) {
        $typewoningfilter == NULL;
    }
    else {
        $typewoningfilter = "type-woning==" . $typewoningfilter;  
    }
    
    if(empty($plaatsfilter)) {
        $plaatsfilter == NULL;
    }
    else {
        $plaatsfilter = "plaats==" . $plaatsfilter;  
    }
    
    if(empty($aannemerfilter)) {
        $aannemerfilter == NULL;
    }
    else {
        $aannemerfilter = "aannemer==" . $aannemerfilter;  
    }
    
    if(empty($kamersfilter)) {
        $kamersfilter == NULL;
    }
    else {
        $kamersfilter = "kamers==" . $kamersfilter;  
    }
    
$myfilter = array ("$archfilter","$typewoningfilter","$plaatsfilter","$aannemerfilter","$kamersfilter");
$comma_separated = implode(",", array_filter($myfilter));

echo $comma_separated;


thanks for your help Bob.

greetings Appeltje]]>
appeltje Jan 14, 2019, 09:33 PM https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563568
<![CDATA[Re: Fill &tvFilters with selection on front-end to filter]]> https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563567 Quote from: BobRay at Jan 14, 2019, 07:10 PM
I'm not sure I understand what you're doing, but maybe this will help. It will prevent PHP errors when the $_POST values are not set and allow you to set a default value for them when they are missing or empty:

$archFilter = $modx->getOption('archfilter', $_POST, 'archfilter default value', true);
$typeWoningFilter = $modx->getOption('typewoningfilter', $_POST, 'typewoningfilter default value', true);

$modx->setPlaceholder('archfilter', $archFilter);
$modx->setPlaceholder('typewoningfilter', $typeWoningFilter);

Hi Bob,

thanks for your replay, i have tried your code but still can't get array.

I have tried it in a different way, see my code. don't know if it is the right one, but it works.

<form class="simplesearch-search-form d-flex ruimte-onder" action="[[~34]]" method="POST">
    <div class="row">
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiearch" id="optiearch"  />
                <option value="" disabled selected>Kies architect</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`architect` &name=`optiearch`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiewoning" id="optiewoning"  />
                <option value="" disabled selected>Kies woning</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`type-woning` &name=`optiewoning`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optieplaats" id="optieplaats"  />
                <option value="" disabled selected>Kies plaats</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`plaats` &name=`optieplaats`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optieaann" id="optieaann"  />
                <option value="" disabled selected>Kies aannemer</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`aannemer` &name=`optieaann`]]
            </select>
        </div>
        <div class="col-lg-2 afb-afst">
            <select class="form-control geenradius" type="text" name="optiekame" id="optiekame"  />
                <option value="" disabled selected>Kies kamers</option>
                [[!GetTvVBM? &tpl=`filterSelectOption` &tvname=`kamers` &name=`optiekame`]]
            </select>
        </div>
        <div class="col-lg-2"><input class="inlog btn geenradius knopbreedte" type="submit" value="Zoekfilter"></div>
        [[!SetZoekFilters]]
    </div>
</form>


then the next to set de placeholders :

<?php
$modx->setPlaceholder('archfilter', $_POST['optiearch']);
$modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);
$modx->setPlaceholder('plaatsfilter', $_POST['optieplaats']);
$modx->setPlaceholder('aannemerfilter', $_POST['optieaann']);
$modx->setPlaceholder('kamersfilter', $_POST['optiekame']);


then the snippet to make filter array, to put in GetPage &tvFilters :

<?php
$arch = $modx->getPlaceholder('archfilter');
$type = $modx->getPlaceholder('typewoningfilter');
$plaa = $modx->getPlaceholder('plaatsfilter');
$aann = $modx->getPlaceholder('aannemerfilter');
$kame = $modx->getPlaceholder('kamersfilter');

    if(empty($arch)) {
        $arch == NULL;
    }
    else {
        $arch = "architect==" . $arch;  
    }
    
    if(empty($type)) {
        $type == NULL;
    }
    else {
        $type = "type-woning==" . $type;  
    }
    
    if(empty($plaa)) {
        $plaa == NULL;
    }
    else {
        $plaa = "plaats==" . $plaa;  
    }
    
    if(empty($aann)) {
        $aann == NULL;
    }
    else {
        $aann = "aannemer==" . $aann;  
    }
    
    if(empty($kame)) {
        $kame == NULL;
    }
    else {
        $kame = "kamers==" . $kame;  
    }
    
$myfilter = array ("$arch","$type","$plaa","$aann","$kame");
$comma_separated = implode(",", array_filter($myfilter));

echo $comma_separated;


This is wath is working at the moment, please feel free to correct me if the code could be faster or better.
Thanks for your replay.

Greetings Appeltje]]>
appeltje Jan 14, 2019, 08:03 PM https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563567
<![CDATA[Re: Fill &tvFilters with selection on front-end to filter]]> https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563559
$archFilter = $modx->getOption('archfilter', $_POST, 'archfilter default value', true);
$typeWoningFilter = $modx->getOption('typewoningfilter', $_POST, 'typewoningfilter default value', true);

$modx->setPlaceholder('archfilter', $archFilter);
$modx->setPlaceholder('typewoningfilter', $typeWoningFilter);
]]>
BobRay Jan 14, 2019, 07:10 PM https://forums.modx.com/thread/104793/fill-tvfilters-with-selection-on-front-end-to-filter#dis-post-563559