Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

render_search_field()

Description

Renders the HTML for the provided $field for inclusion in a search form, for example the
advanced search page. Standard field titles are translated using $lang. Custom field titles are i18n translated.

$field an associative array of field data, i.e. a row from the resource_type_field table.
$name the input name to use in the form (post name)
$value the default value to set for this field, if any
$reset is non-blank if the caller requires the field to be reset

Parameters

ColumnTypeDefaultDescription
$field
$value ""
$autoupdate false
$class "stdwidth"
$forsearchbar false
$limit_keywords array
$searched_nodes array array Array of all the searched nodes previously
$reset ""
$simpleSearchFieldsAreHidden false

Location

include/render_functions.php lines 19 to 859

Definition

 
function render_search_field($field,$value="",$autoupdate=false,$class="stdwidth",$forsearchbar=false,$limit_keywords=array(), $searched_nodes = array(), $reset="",$simpleSearchFieldsAreHidden=false)
    {
    
node_field_options_override($field);
    
    global 
$auto_order_checkbox$auto_order_checkbox_case_insensitive$lang$category_tree_open$minyear$daterange_search$searchbyday$is_search$values$n$simple_search_show_dynamic_as_dropdown$clear_function$simple_search_display_condition$autocomplete_search$baseurl$fields$baseurl_short$extrafooterhtml,$FIXED_LIST_FIELD_TYPES$maxyear_extends_current;
?>
<!-- RENDERING FIELD= echo $field['ref']." ".$field['name'];?> -->


    
// set this to zero since this does not apply to collections
    
if (!isset($field['field_constraint'])){$field['field_constraint']=0;}
      
    
$name="field_" . ($forsearchbar htmlspecialchars($field["name"]) : $field["ref"]);
    
$id="field_" $field["ref"];

    
$scriptconditions=array();
        
    
# Assume the field being rendered should be displayed
    
$displaycondition=true;

    
# If the field being rendered has a display condition
    #  For advanced search, always check the display condition
    #  For simple search, only check the display condition if the field is included in the simple_search_display_condition config array 
    
if ( $field["display_condition"]!="" 
    
&& ( !$forsearchbar || ($forsearchbar && !empty($simple_search_display_condition) && in_array($field['ref'],$simple_search_display_condition)) ) )
        {
        
# Split the display condition of the field being rendered into an array of tests (if there are more than one, they are separated by a ";")
        # Each test is in the form governing field = governing field value 
        #   If the field being rendered is itself a governing field then "On Change" code must be generated for the governing field
        #   If the field being rendered is a governed field then "Checking" code must be generated for each governing field
        
$s=explode(";",$field["display_condition"]);
        
$condref=0;
        foreach (
$s as $condition# Check each individual test
            
{
            
# Assume that the current test does not need to be checked
            
$displayconditioncheck=false;
            
$s=explode("=",$condition);
            
# Process each field to see if it is being referenced in the current test
            
global $fields;
            for (
$cf=0;$cf<count($fields);$cf++) # Check each field to see if needs to be checked
                
{
                
# If the field being processed is referenced in the current test 
                
if ($s[0]==$fields[$cf]["name"]) 
                    {
                    
# The field being processed is a governing field whose value(s) control whether the field being rendered is to be visible or hidden
                    
$display_condition_js_prepend=($forsearchbar "#simplesearch_".$fields[$cf]["ref"]." " "");
                    
                    
# The script conditions array contains an entry for each governing field
                    
$scriptconditions[$condref]["field"]               = $fields[$cf]["ref"];  # add new jQuery code to check value
                    
$scriptconditions[$condref]["name"]                = $fields[$cf]["name"];
                    
$scriptconditions[$condref]['type']                = $fields[$cf]['type'];
                    
$scriptconditions[$condref]['display_as_dropdown'] = $fields[$cf]['display_as_dropdown'];
                    
# Get the node references of the governing field
                    
$scriptconditionnodes get_nodes($fields[$cf]['ref'], null, (FIELD_TYPE_CATEGORY_TREE == $fields[$cf]['type'] ? true false));
                    
                    
$checkvalues=$s[1];
                    
# Prepare an array of values present in the test
                    
$validvalues=explode("|",strtoupper($checkvalues));
                    
$scriptconditions[$condref]['valid'] = array();
                    
$scriptconditions[$condref]['validtext'] = array();
                    foreach(
$validvalues as $validvalue)
                        {
                        
# The validtext array is for checking input values instead of their corresponding node references
                        
$scriptconditions[$condref]['validtext'][] = strtolower($validvalue);

                        
# Convert the value name into a node entry if it is a valid node within the governing field
                        
$found_validvalue get_node_by_name($scriptconditionnodes$validvalue);

                        
# If there is a node which corresponds to that value name then append its node reference to a list of valid nodes
                        
if(!= count($found_validvalue))
                            {
                            
$scriptconditions[$condref]['valid'][] = $found_validvalue['ref'];
                            
                            
# Is the node present in search result list of nodes
                            
if(in_array($found_validvalue['ref'],$searched_nodes))
                                {
                                
# Value being tested is present in the searched nodes array
                                
$displayconditioncheck true;
                                }
                            }
                        }
                
                    
# Suppress this field if none of the nodes (of the values) in the test match the searched nodes array
                    
if (!$displayconditioncheck)
                        {
                        
$displaycondition=false# Do not render field
                        
}

                    
                
// Certain fixed list types allow for multiple nodes to be passed at the same time

                // Generate a javascript function specific to the field being rendered
                // This function will be invoked whenever any governing field changes
                
if(in_array($fields[$cf]['type'], $FIXED_LIST_FIELD_TYPES))
                    {
                        if(
FIELD_TYPE_CATEGORY_TREE == $fields[$cf]['type'])
                            {
                            
?>
                            <!-- SETUP HANDLER FOR GOVERNOR= echo $fields[$cf]['ref']; ?> GOVERNED= echo $field['ref']; ?>-->
                            <script type="text/javascript">
                            var wto;
                            jQuery(document).ready(function()
                                {
                                jQuery('#CentralSpace').on('categoryTreeChanged', function(e,node)
                                    {
                                    // Debounce multiple events fired by the category tree
                                    clearTimeout(wto);
                                    wto=setTimeout(function() {
                                        // Reflect the change of the governing field into the following governed field condition checker
                                        console.log(" echo "DISPCOND CATTREE CHANGEGOVERNOR=".$fields[$cf]['ref'?>");
                                        for (i = 0; i<categoryTreeChecksArray.length; i++) {
                                            categoryTreeChecksArray[i]();
                                        }
                                    }, 200);
                                    });
                                });
                            </script>
                            
                            
// Move on to the next field now
                            
continue;
                            }
                        else if(
FIELD_TYPE_DYNAMIC_KEYWORDS_LIST == $fields[$cf]['type'])
                            {
                            if (
$forsearchbar) {
                                if (
$simple_search_show_dynamic_as_dropdown) {
                                    
$checkname       "nodes_searched[{$fields[$cf]['ref']}]";
                                    
$jquery_selector "select[name=\"{$checkname}\"]";
                                }
                                else {
                                    
$jquery_selector "input[name=\"field_{$fields[$cf]["name"]}\"]";
                                }
                            
?>
                            <!-- SETUP HANDLER FOR GOVERNOR= echo $fields[$cf]['ref']; ?> GOVERNED= echo $field['ref']; ?>-->
                            <script type="text/javascript">
                            jQuery(document).ready(function()
                                {
                                jQuery(' echo $jquery_selector?>').change(function ()
                                    {
                                    // Reflect the change of the governing field into the following governed field condition checker
                                    console.log(" echo "DISPCOND DYNAMKKD CHANGEGOVERNOR=".$fields[$cf]['ref']." CHECK GOVERNED=".$field['ref'?>");
                                    checkSearchDisplayCondition echo $field['ref']; ?>();
                                    });
                                });
                            </script>
                            
                            
}
                            else { 
# Advanced search
                            
?>
                            <!-- SETUP HANDLER FOR GOVERNOR= echo $fields[$cf]['ref']; ?> GOVERNED= echo $field['ref']; ?>-->
                            <script type="text/javascript">
                            jQuery(document).ready(function()
                                {
                                jQuery('#CentralSpace').on('dynamicKeywordChanged', function(e,node)
                                    {
                                    // Reflect the change of the governing field into the following governed field condition checker
                                    console.log(" echo "DISPCOND DYNAMKWD CHANGEGOVERNOR=".$fields[$cf]['ref']." CHECK GOVERNED=".$field['ref'?>");
                                    checkSearchDisplayCondition echo $field['ref']; ?>();
                                    });
                                });
                            </script>
                            
                            
}

                            
// Move on to the next field now
                            
continue;
                            }
                        else
                            {
                            
# Otherwise FIELD_TYPE_CHECK_BOX_LIST or FIELD_TYPE_DROP_DOWN_LIST or FIELD_TYPE_RADIO_BUTTONS
                            
                            # Simple search will always display these types as dropdowns
                            
if ($forsearchbar) {
                                
$checkname       "nodes_searched[{$fields[$cf]['ref']}]";
                                
$jquery_selector "select[name=\"{$checkname}\"]";
                            }
                            
# Advanced search will display these as dropdowns if marked as such, otherwise they are displayed as checkbox lists to allow OR selection
                            
else {
                                
# Prepare selector on the assumption that its an input element (ie. a checkbox list or a radio button or a dropdown displayed as checkbox list)
                                
$checkname "nodes_searched[{$fields[$cf]['ref']}]";
                                
$jquery_selector "input[name=\"{$checkname}\"]";

                                
# If however its a drop down list then we should be processing select elements
                                
If ($fields[$cf]['display_as_dropdown'] == true)
                                    {
                                    
$checkname       "nodes_searched[{$fields[$cf]['ref']}]";
                                    
$jquery_selector "select[name=\"{$checkname}\"]";
                                    }
                      &n