0

I am facing one issue while i'm creating my website. I have a search bar on my website. I tried to type and search in chinese, but the search terms on page that i entered become question mark and symbol. The url also same. I'm wondering how can make it work. Only the search terms become this. Any solution?

Updated: This is the search form that i have(this is a searchbox apply to my multisite).

<div class="search">
<form name="searchform" onsubmit="return !!(validateSearch() && dosearch());" method="get" id="searchform">
<input type="text" name="searchterms" class="terms" id="terms" placeholder="<?php if (is_search()) { ?><?php the_search_query(); ?><?php } elseif (is_home() || is_single() || is_page() || is_archive() || is_404()) { ?>What are you searching for?<?php } ?>">
<select name="sengines" class="state" id="state">
<option value="" selected>Select a State</option>
<?php $bcount = get_blog_count();
global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
if(!empty($blogs)){
    ?><?php
    foreach($blogs as $blog){
        $details = get_blog_details($blog->blog_id);
        if($details != false){
            $addr = $details->siteurl;
            $name = $details->blogname;
            if(!(($blog->blog_id == 1)&&($show_main != 1))){
                ?>
                <option value="<?php echo $addr; ?>?s="><?php echo $name;?></option>
                <?php
            }
        }
    }
    ?><?php } ?>
</select>
<input name="Search" type="submit" value="Search" class="button3">
</form>

</div><!--search-->

Javascript for the search form

function dosearch() {
var sf=document.searchform;
var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);
window.location.href = submitto;
return false;
}

function validateSearch(){
    // set some vars
    var terms = document.getElementById('terms');
    var state = document.getElementById('state');
    var msg = '';

    if(terms.value == ''){
        msg+= 'We were unable to search without a keyword! \n';
    }

    else if(terms.value.length < 3){
        msg+= 'Keyword is too short! \n';
    }

    else if(terms.value.length > 25){
            msg+= 'Keyword is too long! \n';
    }

    else if(state.value == ''){
        msg+= 'Select state to proceed! \n';
    }


    // SUbmit form part
    if(msg == ''){
        return true;
    }else{
        alert(msg);
        return false;
    }

}

This is the search result page(not completed yet!)

2 Answers 2

0

Try using urldecode on search string and your operations on decoded string.

Also check if you are using any other encoding, utf-8, utf-16.....

5
  • Yes! I'm using UTF-8. Only the search terms become worst after clicked the search button. The chinese characters(not the search terms) displaying properly on the page actually. Not sure why.
    – Jornes
    Commented Feb 6, 2017 at 7:49
  • echo utf8_decode(urldecode($_GET['s'])); Commented Feb 6, 2017 at 7:59
  • How to implement this to my search form?
    – Jornes
    Commented Feb 6, 2017 at 8:23
  • This you can do in search.php, while querying posts Commented Feb 6, 2017 at 12:23
  • I'm not really good in php. Will you please show me the way how to do it? As i have the code for the form above. Thank you!
    – Jornes
    Commented Feb 7, 2017 at 8:33
0

I got the solution by myself. What i have done is to get rid of something from the js code. Then, search terms in Chinese characters is successfully displayed.

Below is what has been removed from the code.

var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);

I have removed the escape, so it works now! Sometimes, we need to spend some of time to do the research. Thank you for viewing my question and thank guys who tried to help! I appreciate!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.