add filter for Has Nurse or Support Care
Posted by sarneil on 20 Apr 2010 in Activity log
ML asked to be able to filter search results based on whether either of two boolean values in a record were true. Took a couple of tries to figure out how checkboxes behave with regard to the POST array, but I finally figured it out with help from Greg and Martin
1) To report the status of a checkbox in the POST array and use that in PHP to set the state when the page reloads itself.
If the checkbox is not checked, then no value is sent in the POST array, so the PHP that checks has to check not the value, but if isset($_POST[checkbox_element_id]). If that returns true, then write 'checked="checked"' into the page and if it returns false, then write nothing. If the PHP writes 'checked=""' or includes the checked attribute at all, then the checkbox is checked.
In search.php:
$is_nurse_or_support_care_checked = '';
if (isset($_POST['is_nurse_or_support_care_checked'])) {
$is_nurse_or_support_care_checked = "yes";
}
In includes/searchformbasic.inc:
<label for="is_nurse_or_support_care_checked">Has Nurse or Support Care</label>
<input name="is_nurse_or_support_care_checked" type="checkbox" id="is_nurse_or_support_care_checked" <?php if ($is_nurse_or_support_care_checked == 'yes') {echo ' checked="checked"'; } ?> value="checked" ></input>
To modify the where clause to include only those records in which either of the two affected fields have the value 1 (as opposed to the only other possible value, which is 0)
in search.php:
if (!empty($is_nurse_or_support_care_checked)) {
if (!empty($where)) {$where .= " " . $combine_fields_using_value . " ";}
$where .= "(";
$where .= "(exams.food_rest = '1') ";
$where .= "OR (exams.nursing_care = '1') ";
$where .= ")";
}