How to Limit Characters on Keyword Search in Backend?

3 posts by 2 authors in: Forums > CMS Builder
Last Post: Yesterday at 11:11pm   (RSS)

By Tim - Yesterday at 12:13pm - edited: Yesterday at 12:44pm

Hello mark99,

I think something like this should get you moving in the right direction:

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  require_once "/system/lib/viewer_functions.php";
  
  // If you prefer to just die if the keyword search is greater than 35
  if (isset($_REQUEST['title_keyword'])) {
     if (strlen($_REQUEST['title_keyword']) > 35) {
         dieWith404('Page not found!');
     }
  }

  list($my_listRecords, $my_listMetaData) = getRecords(array(
    'tableName'   => 'my_list',
    'perPage'     => '100',
	'loadCreatedBy' => false,
  ));
?>

Here we are saying that if the value submitted by the form ('title_keyword') is set, and if greater than 35 characters, die with a 404 response.

Another option is that you could also send the user to a custom 404 page through a redirect...

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  require_once "/system/lib/viewer_functions.php";
  
  // If you prefer to just die if the keyword search is greater than 35
  if (isset($_REQUEST['title_keyword'])) {
     if (strlen($_REQUEST['title_keyword']) > 35) {
        header("HTTP/1.0 404 Not Found");
        header("Location: /custom-404.php"); 
        exit();
     }
  }

  list($my_listRecords, $my_listMetaData) = getRecords(array(
    'tableName'   => 'my_list',
    'perPage'     => '100',
	'loadCreatedBy' => false,
  ));
?>

Let me know how that works out for you. 

Tim Hurd
Senior Web Programmer
Interactivetools.com

Perfect, that solved it nicely :). Thanks Tim.