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
[/#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: [RapidWeb] Search with checkbox only shows �last� selected item in search box
By Jason - January 30, 2012 - edited: January 30, 2012
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:
<input type="checkbox" value="Large-scale Hotel" name="establishment[]" />
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Search with checkbox only shows last selected item in search box
By (Deleted User) - January 30, 2012 - edited: January 30, 2012
Re: [RapidWeb] Search with checkbox only shows �last� selected item in search box
By (Deleted User) - January 30, 2012 - edited: January 30, 2012
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
<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 & Breakfast" name="establishment[]" />Bed & 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
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]<<[/#ff0000][/#ff0000] prev</[/#0000ff][/#0000ff]a[/#800000][/#800000]>[/#0000ff][/#0000ff]
<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]
<<[/#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 >>[/#ff0000][/#ff0000]</[/#0000ff][/#0000ff]a[/#800000][/#800000]>[/#0000ff][/#0000ff]
<?[/#0000ff][/#0000ff]php[/#800000][/#800000] else:[/#ff0000][/#ff0000] ?>[/#0000ff][/#0000ff]
next >>[/#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]