Front end search form issues

12 posts by 2 authors in: Forums > CMS Builder
Last Post: January 8, 2016   (RSS)

Hi All,

I’m having a bit of trouble with a few aspects of a front end search function. They're probably easy fixes, but I can’t seem to get my head around the solutions. (Designing searches has never been a strength.)

BACKGROUND:
There's a multi value list field (levels_of_care) in a multi record table (accounts) that get’s its values and labels from the num and category fields of another table.

A) I’d like to filter the results of a front end search of the accounts table to include only those records where there’s a match for one or more of the levels_of_care criteria.

There's also a telltale that echos all of the various search criteria that have been submitted.

B) The search form contains some check boxes, and although I’ve been able to get them to search and to appear correctly in the telltale, I’m curious to know if there’s a more elegant approach then the code I’ve used.

ISSIUES

A) LIST FIELDS
1) the search form only accepts one search value for levels_of _care and I need it to be able to accept multiple values.
2) Although the searches work correctly, the telltale shows the record number value of the $_REQUEST['levels_of_care_match'] instead of the labels as shown in the search pull down..

Here’s the code that I’m using in the search form:

<form method="POST" class="text_font" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<tr>
        <td class="text_font"><b>Choose a Level of Care: </b></td>
        <td colspan="2"><select name = "levels_of_care_match" width="300" class="text_font" style="width: 300px">
            <option value="">Select Which Levels of Care Are Required</option>
            <?php foreach (getListOptions('accounts', 'levels_of_care') as $value => $label2): ?>
            <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['levels_of_care']);?>> <?php echo $label2; ?></option>
            <?php endforeach ?>
          </select></td>
      </tr>
<tr>
        <td class="text_font"><b>&nbsp;</b></td>
        <td align="left" colspan="3"><input type="submit" name="submit" value="Search" ></td>
      </tr>
    </form>


And here’s the code I’m using in a telltale that echo’s the search that has been submitted.
 

<?php
  $searchCriteria = '';

  if (@$_REQUEST['levels_of_care_match']) { $searchCriteria .= "Levels of Care: {$_REQUEST['levels_of_care_match']} - "; }

   $searchCriteria = chop($searchCriteria, ', '); // remove trailing , or spaces
    $searchCriteria = chop($searchCriteria, '- '); // remove trailing - or spaces
 
?>
 
<?php if($count >= 2 || $count == 0 ):?>There are <?php elseif($count == 1):?>There is <?php endif ?><?php echo $count ?> <?php if($count >= 2 || $count == 0 ):?>listings <?php elseif($count ==1):?>listing <?php endif ?>that match your search for:
  <?php if ( @!$searchCriteria ):?>
  All Listings
  <?php else :?>
  <br />
  <?php echo $searchCriteria ?>
  <?php endif ?>


B) CHECK BOXES
Here’s the code added to the search form above to handle a wheelchair_accessible check box:

<tr>
        <td class="text_font"><<b>Wheelchair Accessible: </b></td>
        <td colspan="2"><select name = "wheelchair_accessible" width="300" class="text_font" style="width: 300px">
            <option value="">Choose a value (Optional)</option>
            <option value="1">Yes</option>
            <option value="0">No</option>
         
          </select></td>
      </tr>


And here’s the code added to the telltale for the check boxes.

 if (@$_REQUEST['wheelchair_accessible'] && @$_REQUEST['wheelchair_accessible'] == 1) { $searchCriteria .= "Wheelchair Accessible: Yes - "; }
   if (@$_REQUEST['wheelchair_accessible'] && (@$_REQUEST['wheelchair_accessible'] == 0 || @$_REQUEST['wheelchair_accessible'] == "")) { $searchCriteria .= "Wheelchair Accessible: No - "; }


Help appreciated.

Thanks,

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 ross - January 5, 2016

Hi Jerry

Thanks for posting.  Let's focus on the LIST FIELDS issue first.

It sounds to me like you want someone to be able to select more than one option from your "Levels Of Care" drop down.  There are two things to adjust for this. First is to add "multiple" to the <select> tag and then change the name modifier from "_match" to "_keyword" like this:

<select name = "levels_of_care_keyword" width="300" class="text_font" style="width: 300px" multiple >

Try that and see how it effects your output.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By gkornbluth - January 6, 2016 - edited: January 6, 2016

Hi Ross,

Thanks for your suggestion.

The multiple entry issues seem to be sorted out.

Here's the final code:

<tr>
        <td  align="right" class="text_font"><b>Levels of Care Required:</b><br />Select all applicable</td>
         <td align="left" valign="bottom" colspan="2"><select name = "levels_of_care_keyword"  width="300" class="text_font" style="width: 300px; max-height: 50px;"  multiple>
          
            <?php foreach (getListOptions('accounts', 'levels_of_care') as $value => $label2): ?>
            <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['levels_of_care']);?>> <?php echo $label2; ?></option>
            <?php endforeach ?>
          </select></td>
      </tr>

I changed the telltale code from match to keyword as well, but the telltale now shows only the last entry in the selected keywords (still with the option value (record number) instead of the option label).

Here's the current telltale code:

 if (@$_REQUEST['levels_of_care_keyword']) { $searchCriteria .= "<b>Levels of Care:</b> {$_REQUEST['levels_of_care_keyword']} - "; }

Hope this is as easy a fix.

Best,

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 ross - January 6, 2016

Hi Jerry

What you need is something like this:

$levels_of_care_values =  implode(',', $_REQUEST['levels_of_care_keyword']);

That will give you a comma separated list of all the options selected on the previous page.

Let me know if that works for you.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Hi Ross,

Thanks as always,

I'm assuming that you meant the code to be incorporated into the telltale code below, and I mucked about a bit, but can't seem to figure out exactly how to accomplish that.

 if (@$_REQUEST['levels_of_care_keyword']) { $searchCriteria .= "<b>Levels of Care:</b> {$_REQUEST['levels_of_care_keyword']} - "; }

Best,

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

By gkornbluth - January 6, 2016 - edited: January 6, 2016

Hi Ross,

Thanks for clarifying

Unfortunately, when I try to implement the new code, I get the following error:

Warning: implode(): Invalid arguments passed in /home7/ellescho/public_html/dbtct/directory_results.php on line 124

I can make the error go away by adding $_REQUEST['levels_of_care_keyword'] = array(); in front of your implode code as suggested in a post on stackoverflow.com,

 if (@$_REQUEST['levels_of_care_keyword']) {
      $_REQUEST['levels_of_care_keyword'] = array();
    $levels_of_care =  implode(',', @$_REQUEST['levels_of_care_keyword']);
    $searchCriteria .= "<b>Levels of Care:</b> $levels_of_care - ";
    
 }

but then the $levels_of_care variable does not seem to contain any values at all.

Thanks

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 ross - January 7, 2016

Hi Jerry

My first thought on the error you got is that nothing was selected in the multi select field when you submitted the form.  You can add some extra error checking to make sure the "impode" function doesn't execute if  "levels_of_care_keyword " is empty. 

I'm attaching a simple test script I based my last post on. 

That will show you want I am doing and will hopefully get you on the right track.  The script will run from anywhere on your server and doesn't need CMS Builder.

Let me know any questions or feedback.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Attachments:

multiSearchTest.php 1K

Hi Ross,

Thanks yet again...

I tried adding the extra error checking by including  a check for a hidden field  in the form <input type="hidden" name="save" value="1" />

if (($_REQUEST['save'] == 1) && @$_REQUEST['levels_of_care_keyword']) {
   //  $_REQUEST['levels_of_care_keyword'] = array();
    $levels_of_care =  implode(',', @$_REQUEST['levels_of_care_keyword']);
    $searchCriteria .= "<b>Levels of Care:</b> $levels_of_care - ";
    
 }

But I still have the same issue.(although your test form does work)

I hate to keep asking you to work on this without compensation, so if you feel you want to convert this to a small consulting, that would be OK.

The telltale is supposed to show the result of the multi search as a reminder of what criteria were selected, and since the search fields are populated from a separate database I need the option label to be shown in the telltale instead of the option value (record number) which shows now.

I've attached both the directory search and the directory results pages

You can see the telltale code in question in the directory_results page beginning on line 120

I didn't want to update any of the other code until I got this one working

Best,

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

By ross - January 8, 2016

Hi Jerry

Aside from the fact my example only uses one page and yours splits across two, does my test script simulate the functionality you are aiming for?

Basically, what I am assuming is you have a form submit with a multi-select field and output the values selected in that field. Among other things of course.

If I'm on the right track here, what you'll want to do is simply your pages to the point where it just does this one thing. The first page has a multi-select field on it and the second page displays the values selected.  Then you can start adding back in the rest of your code that was already working.

Does that make sense?

With the consulting, that would only kick in if I am actually doing the coding myself.  We can keep this in the forum if you want to keep working on the code yourself. 

We can keep this in the forum if you want to keep working on the code yourself. Consulting would only kick in if I am actually doing the coding myself.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/