Currently, the Filter Form up to Pods CMS version 1.7.3 still uses the basic form. It has one textbox and one button only. In addition, this filter form can only filter the recordset that returned by its process based on the name field. So I made modification/enhancement by adding combobox that contains of all fields from the table in order to make user easier to choose based which field they will filter, which has default is filter in all fields or any field. Besides that, I also added the search type, whether Match Case or not, Page Limit selection, and the field selection to give user choices sorting the recordset based on the certain field and the certain sort type.
-
Open \pods\core\list_filters.php file, and find this code:
44 45 46 47 48 49
// Display the search box and submit button $search = empty($_GET['search']) ? '' : $_GET['search']; ?> <input type="text" class="pod_search" name="search" value="<?php echo $search; ?>" /> <input type="submit" class="pod_submit" value="<?php echo $label; ?>" /> </form>then replace with this following code:
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
// Display the search box and submit button $search = empty($_GET['search']) ? '' : $_GET['search']; $match = empty($_GET['match']) ? '1' : $_GET['match']; $pagelimit = empty($_GET['limit']) ? '10' : $_GET['limit']; $field = empty($_GET['field']) ? '(Any-field)' : $_GET['field']; $sortby = empty($_GET['sortby']) ? 'id' : $_GET['sortby']; $sorttype = empty($_GET['sorttype']) ? 'ASC' : $_GET['sorttype']; ?> <?php $strField = "SHOW FIELDS FROM `wp_pod_tbl_$datatype`"; $resultField = mysql_query($strField); $numberField = mysql_numrows($resultField); $arrField[0]='(Any-field)'; $strSearchField = ""; for ($i=1; $i<=$numberField; $i++) { $arrField[$i] = mysql_result($resultField, $i-1, "Field"); } echo ("<table bgcolor='#F7F7F7' width='100%'>"); echo ("<tr><td align='right'>Field:</td><td><select name='field'>"); // </td>\n<td> for ($i=0; $i<=$numberField; $i++) { $strSelField = ($arrField[$i]==$field) ? 'selected' : ''; echo ("<option $strSelField value=\"$arrField[$i]\">$arrField[$i]</option>"); } echo ("</select></td>"); echo ("<td align='right'>Match:</td><td><select name='match'>"); $SelAny = ($match=='1')?'selected' : ''; $SelMatch = ($match=='2')?'selected' : ''; echo ("<option $SelAny value='1'>Any Part</option>"); echo ("<option $SelMatch value='2'>Match Case</option>"); echo ("</select></td>"); ?> <td align='right'>Page limit:</td><td><select name='limit'> <?php for ($x = 5; $x <= 50; $x += 5) { ?> <option value="<?=$x?>" <?=($pagelimit==$x )?'selected':''?>><?=$x?></option> <?php } ?> </select></td><td rowspan="2"> <input type="submit" class="pod_submit" value=" <?php echo $label; ?> " /></td> </tr> <tr><td align='right'><?php echo $label; ?>:</td><td><input type="text" size="12" class="pod_search" name="search" value="<?php echo $search; ?>" /></td> <?php echo ("<td align='right'>Sort by:</td><td><select name='sortby'>"); // </td>\n<td> for ($i=1; $i<=$numberField; $i++) { $strSelSortBy = ($arrField[$i]==$sortby) ? 'selected' : ''; echo ("<option $strSelSortBy value=\"$arrField[$i]\">$arrField[$i]</option>"); } echo ("</select></td>"); echo ("<td align='right'>Sort type:</td><td><select name='sorttype'>"); $SelAsc = ($sorttype=='ASC')?'selected' : ''; $SelDesc = ($sorttype=='DESC')?'selected' : ''; echo ("<option $SelAsc value='ASC'>Asc</option>"); echo ("<option $SelDesc value='DESC'>Desc</option>"); echo ("</select></td></tr></table>"); ?> </form>
-
Open \pods\core\Pod.class.php file, and find this code:
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
function findRecords($orderby = 'id DESC', $rows_per_page = 15, $where = null, $sql = null) { $page = $this->page; $datatype = $this->datatype; $datatype_id = $this->datatype_id; $limit = ($rows_per_page * ($page - 1)) . ', ' . $rows_per_page; $where = empty($where) ? '' : "AND $where"; $this->rpp = $rows_per_page; $i = 0; // Handle search if (!empty($_GET['search'])) { $val = mysql_real_escape_string(trim($_GET['search'])); $search = "AND (t.name LIKE '%$val%')"; } // Add "t." prefix to $orderby if needed if (false !== strpos($orderby, ',') && false === strpos($orderby, '.')) { $orderby = 't.' . $orderby; }
then replace with this following code:
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
function findRecords($orderby = 'id DESC', $rows_per_page = 15, $where = null, $sql = null) { $page = $this->page; $datatype = $this->datatype; $datatype_id = $this->datatype_id; $limit = ($rows_per_page * ($page - 1)) . ', ' . $rows_per_page; $match = $_GET['match']; $where = empty($where) ? '' : "AND $where"; $this->rpp = $rows_per_page; $i = 0; // Handle search if (!empty($_GET['search'])) { $val = mysql_real_escape_string(trim($_GET['search'])); // Check which field, added by Masino Sinaga, Sept 25, 2009 if ($_GET['field']!='') { if ($_GET['field']=='(Any-field)') { $strField = "SHOW FIELDS FROM `wp_pod_tbl_$datatype`"; $resultField = mysql_query($strField); $numberField = mysql_numrows($resultField); $arrField[0]='(Any-field)'; $strSearchField = " ("; for ($i=1; $i<=$numberField; $i++) { $arrField[$i] = mysql_result($resultField, $i-1, "Field"); if (($i==1) || (($i<$numberField) && ($i>=1))) { $strSearchField .= ($match=='1') ? " t.$arrField[$i] like '%$val%' OR" : " t.$arrField[$i] like '$val' OR"; } else { $strSearchField .= ($match=='1') ? " t.$arrField[$i] like '%$val%' " : " t.$arrField[$i] like '$val' "; } } $search = " AND ".$strSearchField.") "; } else { $search = ($match=='1') ? "AND (t.".$_GET['field']." LIKE '%$val%')" : "AND (t.".$_GET['field']." LIKE '$val')"; } } else { $search = ($match=='1') ? "AND (t.name LIKE '%$val%')" : "AND (t.name LIKE '$val')"; } } // Check the sortby and sorttype, added by Masino Sinaga, Sept 25, 2009 if ($_GET['sortby']!='') { if ($_GET['sorttype']!='') { $orderby = $_GET['sortby']." ".$_GET['sorttype']; } } // Add "t." prefix to $orderby if needed if (false !== strpos($orderby, ',') && false === strpos($orderby, '.')) { $orderby = 't.' . $orderby; }
Demo:
- http://www.openscriptsolution.com/data/countries/
- http://www.openscriptsolution.com/data/states/
- http://www.openscriptsolution.com/data/bank-in-indonesia/

Recent Comments