Search with checkbox only shows “last” selected item in search box

7 posts by 3 authors in: Forums > CMS Builder
Last Post: February 1, 2012   (RSS)

By (Deleted User) - January 29, 2012

[font "Calibri"]This is my search page:
[/#000000]
[url "http://www.koshertravelinfo.com/kosher-hotels/search-advanced.html"][font "Calibri"]http://www.koshertravelinfo.com/kosher-hotels/search-advanced.html[/#0000ff][/url]

[font "Calibri"]This is my search results page:
[/#000000]
[url "http://www.koshertravelinfo.com/kosher-hotels/kosher-hotel-listing.php"][font "Calibri"]http://www.koshertravelinfo.com/kosher-hotels/kosher-hotel-listing.php[/#0000ff][/url]

[font "Calibri"]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…[/#000000]

Re: [Jason] Search with checkbox only shows last selected item in search box

By (Deleted User) - January 30, 2012 - edited: January 30, 2012

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.

Re: [RapidWeb] Search with checkbox only shows �last� selected item in search box

By (Deleted User) - January 30, 2012 - edited: January 30, 2012

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
$value = $_REQUEST['name']
you would use
foreach ( $_REQUEST['name'] as $value ) {
echo "I found $value!";
}


Hope this helps,

Tom

Re: [Tom P] Search with checkbox only shows last selected item in search box

By (Deleted User) - January 30, 2012

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:

<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.

Re: [Tom P] Search with checkbox only shows last selected item in search box

By (Deleted User) - January 31, 2012 - edited: February 1, 2012

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.

<table style="WIDTH: 100%"[/#000000]

border="1"

cellspacing="1"

cellpadding="0"
>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]td valign="top"

align="left"
><[/#0000ff][/#0000ff]nodesigner[/#800000][/#800000]>[/#0000ff][/#0000ff]

<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->[/#008000][/#008000]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] if[/#ff0000][/#ff0000] ($hotelsMetaData[/#ff0000][/#ff0000]['prevPage'[/#0000ff][/#0000ff]]):[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

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

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

&lt;&lt;[/#ff0000][/#ff0000] prev

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] endif[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

- page
<?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $hotelsMetaData[/#ff0000][/#ff0000]['page'[/#0000ff][/#0000ff]] ?>[/#0000ff][/#0000ff] of <?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $hotelsMetaData[/#ff0000][/#ff0000]['totalPages'[/#0000ff][/#0000ff]] ?>[/#0000ff][/#0000ff] -

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] if[/#ff0000][/#ff0000] ($hotelsMetaData[/#ff0000][/#ff0000]['nextPage'[/#0000ff][/#0000ff]]):[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

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

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

next
&gt;&gt;[/#ff0000][/#ff0000]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] endif[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

<!-- /STEP3: Display Page Links -->[/#008000][/#008000]

</
[/#0000ff]
[/#0000ff]nodesigner[/#800000][/#800000]></[/#0000ff][/#0000ff]td[/#800000][/#800000]>[/#0000ff][/#0000ff]

</[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

</[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>

</
[/#0000ff]
[/#0000ff]table[/#800000][/#800000]><?[/#0000ff][/#0000ff]php[/#800000][/#800000] [/#000000]foreach[/#ff0000][/#ff0000] ($[/#000000]hotelsRecords[/#ff0000][/#ff0000] [/#000000]as[/#ff0000][/#ff0000] $[/#000000]record[/#ff0000][/#ff0000])[/#000000]:[/#ff0000][/#ff0000] ?[/#000000]>[/#0000ff][/#0000ff] [/#000000]

<
[/#0000ff]
[/#0000ff]table style=[/#000000]

"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"
>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]td style=

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

valign="top"

align="center"
><[/#0000ff][/#0000ff]nodesigner[/#800000][/#800000]>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] if[/#ff0000][/#ff0000]($record[/#ff0000][/#ff0000]['images'[/#0000ff][/#0000ff]]):[/#ff0000][/#ff0000]?>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] $upload[/#ff0000][/#ff0000]=$record[/#ff0000][/#ff0000]['images'[/#0000ff][/#0000ff]][0[/#ff0000][/#ff0000]];?>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] if[/#ff0000][/#ff0000]($upload[/#ff0000][/#ff0000]['hasThumbnail'[/#0000ff][/#0000ff]]):[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

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

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

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

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] endif[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]

@


<
[/#0000ff]
[/#0000ff]table style="WIDTH: 125px; HEIGHT: 125px"[/#000000]

border="1"

cellspacing="0"

bordercolor="#333399"

cellpadding="2"

height:=""

width:=""
>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]td style="COLOR: #808080; FONT-SIZE: 14px; FONT-WEIGHT: bold"

valign="middle"

align="center"
>[/#0000ff][/#0000ff]Photo<[/#0000ff][/#0000ff]br[/#800000][/#800000]>[/#0000ff][/#0000ff]

Not
<[/#0000ff][/#0000ff]br[/#800000][/#800000]>[/#0000ff][/#0000ff]

Available
</[/#0000ff][/#0000ff]td[/#800000][/#800000]>[/#0000ff][/#0000ff]

</[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

</[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>

</
[/#0000ff]
[/#0000ff]table[/#800000][/#800000]>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] endif[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]



</[/#0000ff][/#0000ff]td[/#800000][/#800000]>[/#0000ff][/#0000ff]

</
[/#0000ff]
[/#0000ff]nodesigner[/#800000][/#800000]></[/#0000ff][/#0000ff]td[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]td style="BORDER-BOTTOM-COLOR: ; BORDER-TOP-COLOR: ; BORDER-RIGHT-COLOR: ; BORDER-LEFT-COLOR:"

valign="top"

align="left"
><[/#0000ff][/#0000ff]nodesigner[/#800000][/#800000]><[/#0000ff][/#0000ff]a[/#800000][/#800000] href[/#ff0000][/#ff0000]="<?php[/#ff0000][/#ff0000] echo[/#ff0000][/#ff0000] $record[/#ff0000][/#ff0000]['_link'[/#0000ff][/#0000ff]] ?>[/#0000ff][/#0000ff]">[/#0000ff][/#0000ff]

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

</[/#0000ff][/#0000ff]a[/#800000][/#800000]>

</
[/#0000ff]
[/#0000ff]nodesigner[/#800000][/#800000]>[/#0000ff][/#0000ff] [/#000000]<?[/#0000ff][/#0000ff]php[/#800000][/#800000] [/#000000]echo[/#ff0000][/#ff0000] $[/#000000]record[/#ff0000][/#ff0000][[/#000000]'address'[/#0000ff][/#0000ff]] ?[/#000000]>[/#0000ff][/#0000ff] [/#000000]&nbsp;[/#ff0000][/#ff0000]<?[/#0000ff][/#0000ff]php[/#800000][/#800000] [/#000000]echo[/#ff0000][/#ff0000] $[/#000000]record[/#ff0000][/#ff0000][[/#000000]'address2'[/#0000ff][/#0000ff]] ?[/#000000]><[/#0000ff][/#0000ff]br[/#800000][/#800000]>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $record[/#ff0000][/#ff0000]['city'[/#0000ff][/#0000ff]] ?>[/#0000ff][/#0000ff] , <?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $record[/#ff0000][/#ff0000]['state'[/#0000ff][/#0000ff]] ?>[/#0000ff][/#0000ff] &nbsp;[/#ff0000][/#ff0000]<?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $record[/#ff0000][/#ff0000]['zip'[/#0000ff][/#0000ff]] ?><[/#0000ff][/#0000ff]br[/#800000][/#800000]>[/#0000ff][/#0000ff]

<?[/#0000ff][/#0000ff]php[/#800000][/#800000] echo[/#ff0000][/#ff0000] $record[/#ff0000][/#ff0000]['country'[/#0000ff][/#0000ff]] ?></[/#0000ff][/#0000ff]td[/#800000][/#800000]>[/#0000ff][/#0000ff]

<[/#0000ff][/#0000ff]td style=

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

valign="bottom"

align="right"
><[/#0000ff][/#0000ff]span[/#800000][/#800000] lang[/#ff0000][/#ff0000]="EN-GB"><[/#0000ff][/#0000ff]strong[/#800000][/#800000]>[/#0000ff][/#0000ff]Lodging

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

</[/#0000ff][/#0000ff]tr[/#800000][/#800000]>[/#0000ff][/#0000ff]

</[/#0000ff][/#0000ff]tbody[/#800000][/#800000]>

</
[/#0000ff]
[/#0000ff]table[/#800000][/#800000]>[/#0000ff][/#0000ff]

Re: [RapidWeb] Search with checkbox only shows last selected item in search box

By (Deleted User) - February 1, 2012

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:

$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:
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