<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>
<?php $modx->setPlaceholder('archfilter', $_POST['optiearch']); $modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);
<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>
$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);
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);
<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>
<?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']);
<?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;
Quote from: BobRay at Jan 14, 2019, 07:10 PMI'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
<?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;