Selection Box for Different Category Filtering (Public Output)

4 posts by 2 authors in: Forums > CMS Builder
Last Post: May 25, 2017   (RSS)

By gkornbluth - May 24, 2017

Hi Mark,

Here's a recipe from my CMSB Cookbook that might help. '

ALLOWING VISITOR TO SET WHERE VALUES FROM MASTER VALUES LIST

For this example I wanted my client to be able to filter the Exhibition records displayed by choosing possible
project_title 'where' values from a pre-determined list of Exhibition titles. This would insure that all the requests
were consistent when filtering the records to be shown, and would keep all the possible values in a CMSB table, instead
of needing to hard code them into the viewer code.

I also wanted to make sure that I was not creating a security risk as described by Dave Edis from Interactive Tools, who
said:

"By passing a letter (or word or code, it doesn't matter) and testing for that instead of just specifying the order by
in the option value directly, you won't allow users to pass MySQL directly into your program and create a security risk."

To accomplish this task, I created a multi-record editor called master_exhiibtion_list which has only one text field
called title. This way each allowed Title was in it's own record. 

Then in the head of my viewer, (with a lot of help from Jason Sauchuck from Interactive Tools), I inserted the following
code:



<?php
list($master_exhibition_listRecords$master_exhibition_listMetaData) = getRecords(array(
'tableName' => 'master_exhibition_list',

));
?>

<?php
$numToName 
= array(); 
foreach (
$master_exhibition_listRecords as $record){ 
  
$numToName[$record['num']] = $record['title']; 


}
?>

<?php 
 $where 
""
  
?>

<?php foreach ($master_exhibition_listRecords as $record): ?>

<?php if (@$FORM['where'] == $record['num']) { $where $record['title'];}?>
<?php 
endforeach; ?>
   
  
<?php
 
list($client_uploadsRecords$client_uploadsMetaData) = getRecords(array(  
    
'tableName'   => 'client_uploads',  
    
'where'       => " project_title = '$where'",  

  ));
?>

Then for the form that selects the values (again with a lot of help from Jason) I used:

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

<select name="where"> 
<option value=""><span class="body-text-bold">Select</span></option> 
<?php foreach($numToName as $num => $name): ?> 
<option value="<?php echo $num;?>"><?php echo $name;?></option> 
<?php endforeach?> 
</select>

<input type="submit" name="submit" value="Select An Exhibition And Click To View">
</form>

Of course you'll have to modify the code to fit your needs.

There are other recipes about using where values as well.

If you're not a subscriber to the Cookbook, why not take advantage of my 3 month free subscription offer below.

Hope this helps,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By mark99 - May 25, 2017

Thanks Jerry. Think I'll have to take some time to try and get my head around that one as my PHP knowledge is fairly basic but I sort of understand what it's trying to do, although I'm not yet sure how to adapt it to my system.

By gkornbluth - May 25, 2017

Hope it works for you.

The Cookbook has some tutorials also

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php