Jump to content

Help with a code snippet


shmideo

Recommended Posts

Hey guys

 

Been working on a little code to display the word 'Search' is different langages depending on the url, ie. /es etc.

I think I am very close. The code just displays the $ rather the value. Code is below:

 

Thanks

Shnideo

<?php /* Multi Language Search */

$pageURL = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];


if(preg_match("~/de/~",$pageURL)){

$search_language = "Suche";

}elseif(preg_match("~/it/~",$pageURL)){

$search_language = "Ricerca";

}elseif(preg_match("~/sv/~",$pageURL)){

$search_language = "Sökning";

}elseif(preg_match("~/nb/~",$pageURL)){

$search_language = "Søk";

}elseif(preg_match("~/fr/~",$pageURL)){

$search_language = "Recherche";

}elseif(preg_match("~/nl/~",$pageURL)){

$search_language = "Zoeken";

}elseif(preg_match("~/es/~",$pageURL)){

$search_language = "Buscar";

}elseif(preg_match("~/en/~",$pageURL)){

$search_language = "Search";

}else{

$search_language ="Søg";

}

?>

<div id="search">

                <form id="searchform" method="get" action="<?php bloginfo('url'); ?>/">

                    <fieldset>

                    <input id="s" type="text" value= echo $search_language name="s"  class="text" onblur="if(this.value == '') this.value = '$search_language';" onfocus="if(this.value == '$search_language') this.value = '';" />

                    <input id="x" type="submit" value="" class="button" />

                    </fieldset>

                </form>

            </div>
Edited by Zane
Link to comment
Share on other sites

 value= echo $search_language   should be  value="<?php echo $search_language; ?>"

 

Additionally this could be replaced

 onblur="if(this.value == '') this.value = '$search_language';" onfocus="if(this.value == '$search_language') this.value = '';"

with just  placeholder="<?php echo $search_langauge; ?>"

Edited by Ch0cu3r
Link to comment
Share on other sites

Thank you so much Ch0cu3r for that, it works!

Strangely though when clicking on the search the word no long dissapears, so you have to overwrite it for your search query wheres before it cleared when clicked.

 

Thanks

Shmideo

Link to comment
Share on other sites

Forgot to mention when using  placeholder="<?php echo $search_langauge; ?>"  you wont need  value="<?php echo $search_langauge; ?>"

So your search box will be just

                    <input id="s" type="text" name="s" class="text" placeholder="<?php echo $search_language; ?>" />
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.