Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example filter form with pagination
<?php namespace ProcessWire;
$filter = "";
$form = $modules->InputfieldForm;
$form->attr("action", $page->url);
$form->attr("method", "get");
// select with sort options
$f = $modules->InputfieldSelect;
$f->attr("name", "sort");
$f->label = "Sort";
"-title" => "descending",
"title" => "ascending"
// submit button
$f = $modules->InputfieldSubmit;
$f->attr("name", "filter");
// process form
// process form input and populate fields
// if sort is not empty
if($form->get("sort")->value) {
// build filter and add to whitelist so it gets picked up by pagination
$input->whitelist("sort", $sanitizer->text($form->get("sort")->value));
$filter .= ",sort=" . $input->whitelist("sort");
$result = $pages->find("template=basic-page, limit=2{$filter}");
$content .= "<h2>Show Results</h2>";
if(!$result->count) {
$content .= "<p>no results</p>";
} else {
foreach($result as $res){
$content .= "<p>$res->title<br>$res->url</p>";
$content .= $result->renderPager();
$content .= $form->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.