Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Search with checkbox only shows “last” selected item in search box

 

 


RapidWeb
User

Jan 29, 2012, 4:11 PM

Post #1 of 7 (861 views)
Shortcut
Search with checkbox only shows “last” selected item in search box Can't Post

This is my search page:
http://www.koshertravelinfo.com/kosher-hotels/search-advanced.html

This is my search results page:
http://www.koshertravelinfo.com/kosher-hotels/kosher-hotel-listing.php

Part of the search form has multiple check boxes. When selecting more than one checkbox, only the LAST selected type will show in the results. For example, selecting Large-scale Hotel and Vacation Home / Villa will only show Vacation Home / Villa types in the result. Please help…


Jason
Staff / Moderator


Jan 30, 2012, 10:21 AM

Post #2 of 7 (842 views)
Shortcut
Re: [RapidWeb] Search with checkbox only shows �last� selected item in search box [In reply to] Can't Post

Hi,

This is happening because they all have the same name (establishment). Selecting one value overwrites the previous value in the array. If you want to be able to select multiple values, you need to make establishment an array by adding [] to the name. For example:



Code
 
<input type="checkbox" value="Large-scale Hotel" name="establishment[]" />


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 

(This post was edited by Jason on Jan 30, 2012, 10:21 AM)


RapidWeb
User

Jan 30, 2012, 3:16 PM

Post #3 of 7 (837 views)
Shortcut
Re: [Jason] Search with checkbox only shows last selected item in search box [In reply to] Can't Post

Thank you for your prompt reply. I added the [] brackets as instructed (to allow multiple selections) but it does not work. In fact, it now completely ignores "Establishment". It ignores this filter. Please help.


(This post was edited by RapidWeb on Jan 30, 2012, 3:37 PM)


Tom P
User


Jan 30, 2012, 3:21 PM

Post #4 of 7 (833 views)
Shortcut
Re: [RapidWeb] Search with checkbox only shows �last� selected item in search box [In reply to] Can't Post

Hi RapidWeb,

Adding square brackets to the end of a name for an input adds each value under that name to an array in POST.

When retrieving the data, you have to read it as an array as well, so instead of

Code
$value = $_REQUEST['name']

you would use

Code
foreach ( $_REQUEST['name'] as $value ) { 
echo "I found $value!";
}


Hope this helps,

Tom


(This post was edited by Tom P on Jan 30, 2012, 3:56 PM)


RapidWeb
User

Jan 30, 2012, 3:34 PM

Post #5 of 7 (832 views)
Shortcut
Re: [Tom P] Search with checkbox only shows last selected item in search box [In reply to] Can't Post

Thank you for your help. I am not a programmer. Can you give it to me in simple format? Below is part of my search form:


Code
  

<input type="checkbox" value="Large-scale Hotel" name="establishment[]" />Large-scale Hotel<br>

<input type="checkbox" value="Small-scale Hotel" name="establishment[]" />Small-scale Hotel<br>

<input type="checkbox" value="Motel" name="establishment[]" />Motel<br>

<input type="checkbox" value="Country Inn" name="establishment[]" />Country Inn<br>

<input type="checkbox" value="Bed &amp; Breakfast" name="establishment[]" />Bed &amp; Breakfast<br>

<input type="checkbox" value="Condominium" name="establishment[]" />Condominium<br>

<input type="checkbox" value="Cabin/Cottage" name="establishment[]" />Cabin/Cottage<br>

<input type="checkbox" value="Ranch" name="establishment[]" />Ranch<br>

<input type="checkbox" value="Vacation Home / Villa" name="establishment[]" />Vacation Home / Villa<br>

<input type="checkbox" value="Resort" name="establishment[]" />Resort<br>



What am I doing wrong? All other fields in this advanced form work fine.


RapidWeb
User

Jan 31, 2012, 3:04 PM

Post #6 of 7 (806 views)
Shortcut
Re: [Tom P] Search with checkbox only shows last selected item in search box [In reply to] Can't Post

Sorry for Bumping this post.

Thank you Dave and Tom for your help.

I am not sure what Tom meant in his reply. Is it that I also have to change the Result Page,
not just the search form? If so, please let me know what to change in the result page.
I am including part of the code for the result page showing the listings.

The search page is a simple HTML page that has a very basic FORM used for the search.
I have used these type of search forms on all my CMSB sites. However, since we are now
trying to target more local real estate clients, we do have a need for a checkbox to be able
to search for more than one result whitin the same field.


Code
   

<table style="WIDTH: 100%"

border="1"

cellspacing="1"

cellpadding="0"
>

<tbody>

<tr>

<td valign="top"

align="left"
><nodesigner>

<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->

<?php if ($hotelsMetaData['prevPage']): ?>

<a href="<?php echo $hotelsMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>

<?php else: ?>

&lt;&lt; prev

<?php endif ?>

- page
<?php echo $hotelsMetaData['page'] ?> of <?php echo $hotelsMetaData['totalPages'] ?> -

<?php if ($hotelsMetaData['nextPage']): ?>

<a href="<?php echo $hotelsMetaData['nextPageLink'] ?>">next &gt;&gt;</a>

<?php else: ?>

next
&gt;&gt;

<?php endif ?>

<!-- /STEP3: Display Page Links -->

</
nodesigner></td>

</tr>

</tbody>

</
table><?php foreach ($hotelsRecords as $record): ?>

<
table style=

"BORDER-BOTTOM: #ff0000 1px solid; BORDER-LEFT: #ff0000 1px solid; WIDTH: 100%; BORDER-COLLAPSE: collapse; BORDER-TOP: #ff0000 1px solid; BORDER-RIGHT: #ff0000 1px solid"

border="0"

cellspacing="1"

cellpadding="3"
>

<tbody>

<tr>

<td style=

"BORDER-BOTTOM-COLOR: ; BORDER-TOP-COLOR: ; WIDTH: 130px; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR:"

valign="top"

align="center"
><nodesigner>

<?php if($record['images']):?>

<?php $upload=$record['images'][0];?>

<?php if($upload['hasThumbnail']): ?>

<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" alt="" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" hspace="3" align="top" /></a><br/>

<?php else: ?>

<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" hspace="3" align="top" /><br/>

<?php endif ?>

<?php else: ?>

@


<
table style="WIDTH: 125px; HEIGHT: 125px"

border="1"

cellspacing="0"

bordercolor="#333399"

cellpadding="2"

height:=""

width:=""
>

<tbody>

<tr>

<td style="COLOR: #808080; FONT-SIZE: 14px; FONT-WEIGHT: bold"

valign="middle"

align="center"
>Photo<br>

Not
<br>

Available
</td>

</tr>

</tbody>

</
table>

<?php endif ?>



</td>

</
nodesigner></td>

<td style="BORDER-BOTTOM-COLOR: ; BORDER-TOP-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR:"

valign="top"

align="left"
><nodesigner><a href="<?php echo $record['_link'] ?>">

<h3><span style="FONT-SIZE: 11pt"><?php echo $record['name'] ?></span></h3>

</a>

</
nodesigner> <?php echo $record['address'] ?> &nbsp;<?php echo $record['address2'] ?><br>

<?php echo $record['city'] ?> , <?php echo $record['state'] ?> &nbsp;<?php echo $record['zip'] ?><br>

<?php echo $record['country'] ?></td>

<td style=

"BORDER-BOTTOM-COLOR: ; BORDER-TOP-COLOR: ; WIDTH: 200px; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR:"

valign="bottom"

align="right"
><span lang="EN-GB"><strong>Lodging

Classification:
</strong><br></span><?php echo join(', ', getListLabels('hotels', 'establishment', $record['establishment'])); ?></td>

</tr>

</tbody>

</
table>



(This post was edited by RapidWeb on Feb 1, 2012, 4:59 AM)


Tom P
User


Feb 1, 2012, 10:14 AM

Post #7 of 7 (790 views)
Shortcut
Re: [RapidWeb] Search with checkbox only shows last selected item in search box [In reply to] Can't Post

Hi RapidWeb,

Since you're trying to create a search query for one field that will look for several keywords you'll need to combine the data from the array and output it as a string before the search is performed.

All this happens before the records are loaded by CMSB (normally right at the start of a page).

To create a "where" statement that will search for each checked keyword in the establishment field, try the following:


Code
   
$selected_establishments_where_statement = '';

if ( @$_REQUEST['establishments'] ) {

$selected_establishments_where_statement = '(';

foreach ( $_REQUEST['establishments'] as $establishment ) {

$selected_establishments_where_statement.= "establishment='".$establishment."' OR ";

}

$selected_establishments_where_statement = substr( $selected_establishments_where_statement,0,-4).")";

}


The above will produce a string along the lines of "(establishment='Hotel' OR establishment='Shop' OR establishment='Shop')" which you can drop into the getRecords function at the start of the page:

Code
 
list($hotelsRecords,$hotelsMetaData) = getRecord(array(
'tableName' =>**TABLE**,
'where' => $selected_establishments_where_statement,
));


The above is an example, you may have other options set in your call.

Hope this helps,

Tom