CodeIgniter Forums

Full Version: Changing filter settings - combining http-post values, session-values, and default-values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi there CodeIgniter community! Smile

I am having trouble finding the most suited way to deal with the following problem;

In my view I would like to present a list of checkboxes so that the user can enable/disable a certain filter setting.

When sent to my controller (using post) I need to set some session-data which I can use when calling my model to activate the chosen settings.

Pretty straight forward for now.. But then the question is: How will I map previous set session-data with my own default settings.

For example, I have a filter list with different regions:
Quote: - NorthX
- SouthY
- Suburbs
- DownTown

When the user selects the checkbox in front of Suburbs and Downtown, we will set the session-variables in the controller accordingly :
Quote:$data['filter_list'] = array(
'N' => array ( 'name' => 'NorthX',
'show' => false) ,
'S' => array ( 'name' => 'SouthY',
'show' => false) ,
'SB' => array ( 'name' => 'Suburbs',
'show' => true),
'DT' => array ( 'name' => 'DownTown',
'show' => true)

Then, back in the view we can regenerate our checkboxes:
foreach ($filter_list as $filter_item) {

$data = array(
'name' => $filter_item['name'],
'id' => $filter_item['name'],
'value' => !$filter_item['show'], //invert the value we had.
'checked' => $filter_item['show'],
'style' => 'margin:1px',

echo form_checkbox($data);
echo $filter_item['name'];
echo "<br/>";

The question is, how do we map these things nicely back and forth (what if we add or remove filters, etc?).

Hope my question is somewhat clear.

Thanks in advance for any time I wasted Smile


El Forum

I have the feeling my question is not clear enough.. is that the fact?

El Forum