set default name_min and name_max values

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 18, 2013   (RSS)

By Joef5 - March 14, 2013

I am trying to create a page that displays search results using the fieldname_min and fieldname_max values.  This part works well.  However, if I access that page without the form to send the min and max values

I get returned all results from the table.

I've tried this:

$width_min = $_POST['width_min'];    
if (!isset ($_POST['width_min']))
    {
        $width_min = 36 ;
    }    

doing the same with the width_max

If I arrive at the page via form, all works well.

If I arrive at the page with a link that includes all the variables in the link (rather long and unattractive) all works well.

Can't arrive at the page and have a limited display. I've tried a few other approaches with the same results. Any ideas?

Hi,

I would do something like this:

  //If the form hasn't been submitted, set default values
  if (@!$_REQUEST['searchData']){
    $_REQUEST['num_min']  = 10 ;
  }

  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => true,
  ));

?>


<!-- This hidden input is just used to detect if the form has been submitted -->
<input type="hidden" name="searchData" value="yes" />
<input type="text" name="num_min" value="" />

<input type="submit" name="submit" value="Search" />
</form>


<?php showme($blogRecords); ?>

So I'm using the searchData variable in the form to detect if the form has been submitted. If it hasn't then I set the $_REQUEST['num_min'] value, and the getRecords function will use this to filter its result. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com