We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Help with search widget | Forum

Jose
Jose Nov 8 '13
Hi

I have a search widget for search groups by name.I would like that when someone introduce any word in the search text box automatically a list of results appears, just like in the attached image. I want just the same functionality that the existing Search Plus Plugin (http://www.oxwall.org/store/item/284) but in my case I want to use the search textbox from the widget.
The query is working fine and retrieves the results, but I´m facing a problem with the results menu not appearing due to the '$script' var from search_widget.php. I need somehow to link this var to the searchform but don´t know how.

I tried to do something like this:
    $this->assign('script', $script);
or this
   ow::getDocument()->appendBody($script);
    
but unsuccessfully. Could someone help me with this??
Many thanks!!


The code related is this:

INIT.PHP
    
    OW::getRouter()->addRoute(new OW_Route('search', 'search', "SEARCH_CTRL_Query", 'index'));
    OW::getRouter()->addRoute(new OW_Route('search.indexquick', 'quickquery', "SEARCH_CTRL_Query", 'ajax_search_method'));
    
SEARCH_QUERY.PHP

    class SEARCH_CTRL_Query extends OW_ActionController
    {
        public function ajax_search_method()
        {
        ...
        }
    }
    
SEARCH_WIDGET.PHP

    public function onBeforeRender()
    {    
        $data="";
        $curent_url=OW_URL_HOME;
        
        $data .= "<form id=\"searchform\" metod=\"get\" action=\"".$curent_url."query\" style=\"display:inline;\">";
        $data .= "<input id=\"query\" name=\"query\" style=\"display:block;\" type=\"text\" value=\"".stripslashes(OW::getLanguage()->text('search', 'tips_default_sugestion'))."\" onblur=\"if(this.value == '') { this.value='".stripslashes(OW::getLanguage()->text('search', 'tips_default_sugestion'))."'};\" onfocus=\"if (this.value == '".stripslashes(OW::getLanguage()->text('search', 'tips_default_sugestion'))."') {this.value=''};\" autocomplete=\"off\" spellcheck=\"false\" >";
        $data .= "</form>";            

        $script .= "<style media=\"all\">\n
        .search_dropdown_hover:hover{background-color:#eee;color:#222;}\n
        </style>\n";

        $script .= "<script type=\"text/javascript\">\n";
        
            $script .= "$(document).ready(function() {";
            $script .= "$('.ow_console .ow_console_body div div').first().before('".$data."'); ";

                $('#query').keyup(function(event) {
                    var valuekey = event.charCode;
                    var c = String.fromCharCode(event.which);
                    if ($(this).val().length>1){

                        $.ajax({
                            type     : 'POST',
                            url      : '".$curent_url."quickquery',
                            data     : {
                                query : $(this).val(),
                                action : 'search'
                            },
                            success : function(msg) {
                                ...
                            },
                            complete : function(r) {
                                ...
                            },
                            error:    function(error) {
                            }
                        });
                        
                        $('#searchform').attr('action', '".$curent_url."query/search');
                        ...
                    }
                });
            })
        ";
        $script .= "</script>\n";

        $this->assign('data', $data);        
    }
The Forum post is edited by Jose Nov 8 '13
Attachments:
  search plugin.png (490Kb)
Daisy Team
Daisy Dec 10 '13
Jose, you can use the standard method: OW::getDocument()->addOnloadScript($script);

When we checked your code we've noticed that you are not using our standard methods at all. We want to warn you that this may lead to negative consequences.

Anyway, we suggest that you download our new Plugin Skeleton plugin to see how the forms and widgets work. Here is URL to the Store item: http://www.oxwall.org/store/item/695