Forums » Filtering Simple Search HTML

RSS feed for this topic

Info

  1. I want to add a 'placeholder' attribute to the search input field (without using javascript), but I cannot seem to get this filter, located in custom.php, to take:

    /*
    Filtering Omeka's Simple Search function to display default message
    Uses HTML5 'placeholder' attribute
    Browser support will vary
    */
    add_filter('simple_search','my_simple_search');
    function my_simple_search($html,$buttonText = "Search", $formProperties=array('id'=>'simple-search'), $uri = null)
    {
        // Always post the 'items/browse' page by default (though can be overridden).
        if (!$uri) {
            $uri = uri('items/browse');
        }
    
        $searchQuery = array_key_exists('search', $_GET) ? $_GET['search'] : '';
        $formProperties['action'] = $uri;
        $formProperties['method'] = 'get';
        $html  = '<form ' . _tag_attributes($formProperties) . '>' . "\n";
        $html .= '<fieldset>' . "\n\n";
        $html .= __v()->formText('search', $searchQuery, array('name'=>'textinput','class'=>'textinput','placeholder'=>'Login to Search Items'));
        $html .= __v()->formSubmit('submit_search', $buttonText);
        $html .= '</fieldset>' . "\n\n";
    
        // add hidden fields for the get parameters passed in uri
        $parsedUri = parse_url($uri);
        if (array_key_exists('query', $parsedUri)) {
            parse_str($parsedUri['query'], $getParams);
            foreach($getParams as $getParamName => $getParamValue) {
                $html .= __v()->formHidden($getParamName, $getParamValue);
            }
        }
    
        $html .= '</form>';
        return $html;
    }

    I also tried removing all but the $html vars, but I think the issue is that the filter is just not registering at all for some reason.

    What's missing here?

    Thanks -- E

  2. The problem here is that there is no "simple_search" filter.

    Since your filter function is already written to completely replicate and replace the simple_search code with your modified version, it will probably be easiest for you to just replace your theme's call to simple_search with one to your custom my_simple_search function. That wouldn't require any filters at all.

  3. Oh right. Duh. Thanks.

Reply

You must log in to post.