Search Form Zen, Using jQuery, with WordPress and Drupal Examples

January 6, 2009

…after all, everything is instantly cooler with the word ‘Zen’ tacked onto it, especially if you add a picture of some cheesy stones nearby…

In one of my earliest blog posts, I described an approach to customizing a search form that I employ on many of my sites. Instead of having a search form that consists of three elements: a label, text input field, and submit button, I like to reduce everything to just the text field with the label inside it, as you can see on the right hand column of this very blog. This frees up room, and requires less mouse work on the part of the user.

The Fundamental Approach from Mambo

To make this work properly, you need to use Javascript to allow the following behavior:

  • By default, the text box either contains some ‘label’ text like ‘searching…’ or alternately, a search that has just been executed.
  • When the user clicks on the search box, the default label text disappears.
  • When the user clicks off of the search box, it will retain what was entered, or if nothing was entered, return to the default label text.

I originally saw this basic functionality on the Mambo CMS site, and because I don’t like to needlessly duplicate work (otherwise known as laziness), I decided to completely and shamelessly rip off their source:

  <input class="search" 
         onblur="if(this.value=='') this.value='search...';" 
         onfocus="if(this.value=='search...') this.value='';" />

More recently, however, I have been using jQuery and have been moving toward implementing Javascript unobtrusively, and so, I decided to explore re-implementing this approach accordingly.

Re-implementing in jQuery

The first step was to move this functionality out into a function, at which point, it became immediately obvious how I could make this approach more flexible and reusable:

function prepare_search_form(selector, default_string, search_term) {
  // what should the default label text be?
  var default_term = 'search...'
  if (default_string && default_string != '') {
    default_term = default_string;
  // lets make sure we are starting fresh
  // set the label text to either the default, or the search string
  if (search_term != '') {
  } else {

  // add the click on, click off behavior
    function() {
     if ($(selector).val() == default_term) {
    function() {
     if ($(selector).val() == '') {

This function will allow me to pass in the CSS-like jQuery selector for the text box I want to affect, it will allow me to specify the default label text (or default to ‘search…’ if I don’t specify it), and will further give me the option to include a search string that has just been executed for display in the text box, if appropriate. Even if you aren’t familiar with jQuery, its fairly evident how this code is working. The use of ‘sensible defaults’ is the influence of Ruby on Rails showing, as this makes the function API as simple and convenient as possible.

So, for the following basic search form:

<form id="searchform" action="search.php">
  <input type="text" 
         name="searchword" />

I could enable this basic functionality by adding this Javascript code:

$(document).ready(function () {
  prepare_search_form('#searchform :text');

Now I have a reusable function I can add to any software I’m using. But just to make things more interesting, let’s look at some more specific examples using WordPress and Drupal.

WordPress Search Form Zen

To begin on some common ground, I am going to customize the default WordPress theme, located at /wp-content/themes/default . Although I think we can assume that the theme may be customized pretty thoroughly in a typical situation, I am going to try to impact the existing files as little as possible, just for the sake of cleaner code.

Obviously you will need to download jQuery and place it in this theme directory.

The search form looks like this (from the searchform.php file):

<form method="get" id="searchform" action="http://localhost">
  <div><input type="text" value="" name="s" id="s" />
       <input type="submit" id="searchsubmit" value="Search" />

I don’t see any existing external Javascript files, so I will put my reusable function and its invocation code in a file in the default theme directory called common.js:

function prepare_search_form(selector, default_string, search_term) {
  // what should the default label text be?
  var default_term = 'search...'
  if (default_string && default_string != '') {
    default_term = default_string;
  // lets make sure we are starting fresh
  // set the label text to either the default, or the search string
  if (search_term != '') {
  } else {

  // add the click on, click off behavior
    function() {
     if ($(selector).val() == default_term) {
    function() {
     if ($(selector).val() == '') {

$(document).ready(function () {

Include this in the theme by adding the appropriate script tag within the <head> tag in header.php, along with a script tag with the path to your jQuery download:

<script type="text/javascript" src="/wp-content/themes/default/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="/wp-content/themes/default/common.js"></script>

Then, we can hide the superfluous submit button by adding the following CSS to style.css:

#searchsubmit {
  display: none;

Now, its probably a little more usable to make it so that when a search is executed, the search terms are shown in the search box. In that case, instead of putting the call to the prepare_search_form function into the commons.js file, I would move it into the footer.php file, right above the closing </body> tag:

$(document).ready(function () {
  prepare_search_form('#s', 'search...', '<?php echo htmlentities(html_entity_decode($_GET['s'])); ?>');

The reason for moving this into a PHP script is so we can easily get access to the search string through PHP’s $_GET super global variable and do some basic anti-XSS (cross site scripting) manipulation on the string before displaying it. I’m not sure this is purely unobtrusive Javascript anymore, but it is at least pragmatic. For a more comprehensive XSS filtering function in PHP, check out this site.

Drupal Search Form Zen

The Drupal implementation is a little easier in some ways.

Assuming that you have turned on the search form ‘block’, you can simply configure the block through the appropriate Drupal admin screens to not show the the block label. Otherwise, the following CSS will hide both the block label and search form submit button:

#search-block-form label, 
#search-block-form input.form-submit {
  display: none;

If you’ve read my blog in the past, it will come as no surprise that I use the Blueprint theme for Drupal which integrates the Blueprint CSS framework. For that theme, this custom CSS will go into the css/style.css file.

Drupal comes pre-installed with jQuery, so you don’t need to download it and include it separately–it’s already available to us. The Blueprint theme also has a scripts/general.js file that makes for a logical place to include the above prepare_search_form() function. Again, the goal here is to try to add this functionality in a way that makes the most sense in the environment we are in.

Now, because by default the search results page displays its own search box with the appropriate search terms added, I tend not to duplicate this functionality in the block search form, preferring the bare bones implementation of prepare_search_form(), which can also be tacked onto the scripts/general.js file:

$(document).ready(function () {
  prepare_search_form('#search-block-form :text');

But if you want to go that extra mile in your block search form, you will need to know a few Drupal API functions. To get the search terms entered by the user, call the search_get_keys() function. And for XSS filtering, Drupal provides a robust function for that with filter_xss(). So the complete implemenation in the Blueprint theme can be achieved by adding the following to the page.php file, just before the closing </body> tag:

$(document).ready(function () {
  prepare_search_form('#search-block-form :text', 'search...', '<?php echo filter_xss(search_get_keys()); ?>');

Wrapping Up…

Once you start down this road, its easy to think of other ways to further enhance the search form using jQuery, perhaps the most obvious being an autocomplete feature. Please share your ideas for improving what I’ve done here.


Comment by ionz149
2009-02-08 12:57:18

Awesome, this worked out quite nicely. I just had to add a default value to the search input and it worked fine. Thanks

Comment by My Site
2012-09-22 05:09:47

If you want to remedy impotence you don’t require medicines, you can get a difficult hard-on by taking the enclosed herbal remedies and not only do they get you a harder hard-on, these herbal remedies will do something which drugs simply can’t do and that’s improve your libido in the same time – lets take a look at how they work.

Herbal remedies about the other hand, improve your libido so you benefit from the complete sexual encounter.

Many males get frustrated when they take drugs simply because there is no improve in sex drive and they require manual stimulation from the penis to obtain hard.

Nitric oxide performs the vital function of opening up the blood vessels which lead into the penis, so they are wide enough to consider the increased quantity of blood in, to stiffen the penis.

Firstly to get a hard erection, you have to have high levels of nitric oxide produced in the physique and the cause for this is easy – no hard-on can consider place if amounts are as well low.

Testosterone is the key male sexual intercourse hormone and is needed for sex generate and sexual stamina and also the great news is – Horny Goat Weed and Cnidium (which we have already mentioned) will give amounts a boost.

You should also nevertheless consider Tribulus, because not only is it the best testosterone boosting herb, it also contains a unique blend of nutrients which improve sex drive and increase intensity and pleasure from orgasm.

If you want to cure impotence quickly and naturally, you are able to get all the above herbs within the best organic erection supplements and they’ll
get you a harder hard-on and also improve your sex drive in the same time –
attempt them and you’ll be glad you did.

he reason herbal remedies are a much better option to man made medicines is – they have no harmful side impacts and simply because they increase sex drive which can be something guy created drugs merely cannot do, lets consider a look at how the herbs function.

If you would like to obtain an hard-on, you need to increase your levels of nitric oxide. Nitric oxide is the key organic chemical which permits an erection to arrive to fruition – no erection can consider place without it.

Prescription drugs do this but you don’t require them, the herbal remedies Horny Goat Weed,
ginseng and Cnidium, will do this too as well as better
news is – they do it safely and normally.

Herbal remedies can get you a hard hard-on and treat impotence normally – but they can also improve your libido which
can be important, for the total all round sexual experience.

Numerous men are left frustrated by man made
drugs because, they get them difficult but they frequently require manual stimulation
and this leads to an incomplete sexual encounter.

The good news is – herbs can get you hard, without guide
stimulation plus they do this in a number of methods that are outlined

Testosterone is required for sexual stamina andlibido and Horny Goat Weed and Ginseng (which we have already pointed out) increase amounts but you ought
to also take another couple of herbs which
are Tribulus and Tonkgat Ali.

Last bit not least, the mind also plays a crucial role
in terms of sexual health and if you are stressed, anxious worried or depressed, you won’t be able to focus on sexual intercourse.

You can consider herbal remedies that will improve your mood and two great ones are – Maca and Ginkgo Biloba which both improve mood and give the physique an energy boost at the exact same time.

Within the greatest organic libido supplements and not just will they treat impotence and give you a difficult hard-on, they may also enhance sexual intercourse drive and overall levels of wellness in the same time.

mental impotence is nearly guaranteed to effect men a minimum of as soon as within their existence. Prior to individuals didn’t see this as an actual concern, they simply chalked it up to old age.

But in today’s society this is really treated as a problem. There are numerous ways for people to recover from mental impotence.

Via recent years mental treatments have come a long way via long arduous research and practice. Now that we know both the reasons for that difficulties and how to alleviate them, it’s
imperative that you consider advantage of them.

A large problem that can trigger mental impotence is
either related to a past concern or it’s temporary. It can really be a cycle of fear.

A single issue can outcome within the fear of re-occurrence can produce anxiety which will cause the initial problem just as we feared. Even tough this kind of mental impotence is fairly stream lined.

You ought to never be ashamed of this problem, and numerous males around the world suffer from it every single day. This really is the result of your emotions effecting you physically.

A great way to solve this issue would be to turn out to be relaxed prior to you turn out to be actual. Music and atmosphere is an excellent way to get into a seductive mood. Points such as these are excellent for lowering tension which may cause the difficulties.

Also you’ll need to become wary of exactly how much you are consuming.
A man can lose his ability to become aroused while drinking
alcohol. No matter what you do, too a lot alcohol can kill
it for you.

If depression is the cause you are suffering, it is greatest
to solve that issue before you are able to use a real physical relationship.

Basically psychological impotence stems from a problem with your psychological outlook.

You’ll not preform well at all if you’re depressed.
Also, you have to realize that other relationship
problems can stem from depressive disorders.

But all in all of the best way to deal with psychological
impotence would be to visit your physician. The
physician will let you know what you can do to offer with your problems and how you can go about treating it.

Recognize that you aren’t alone, and also you have many routes about the path of curing your psychological impotence. Do not let embarrassment keep you from finding out how to deal with this problem.

If you want to remedy impotence naturally, the great news is you are able to and not only can you obtain a difficult erection, just like you can with guy made medicines; herbal cures will improve your sex drive and your general degree of wellness which is something prescription drugs merely cannot do.

Guy created medicines improve nitric oxide secretion and allow more blood into the penis but so Ginseng, Cnidium and Horny Goat Weed which being organic herbs have none of the side impacts of guy made drugs.

If you would like to remedy impotence, you should improve your levels of nitric oxide because nitric oxide regulates blood flow to the penis and it does this by relaxing and widening the blood vessels which supply the penis with blood.

Many males who consider man made drugs obtain a hard hard-on but have no sexual desire plus they wind up needing guide stimulation to obtain an hard-on and this really is frustrating.

If you want to enjoy the all round sexual encounter you have to use a strong sex drive and herbs can improve this as well.

Herbal remedies increase sex drive simply because they increase testosterone and also the Ginseng and Horny Goat Weed are excellent testosterone boosters but you should also take Trubulus which can be seen as the greatest testosterone enhancing herb of all.

The best herbal sex pills for men that will give you better sexual health and better amounts of wellness at the exact same time – so if you want to cure impotence naturally attempt them and get a lot more from sexual intercourse and more from life.

Unfortunately many males will suffer diabetes impotence prior to they do something about their blood sugar degree. The diabetic includes a poison in their bloodstream called glucose.

Diabetic issues impotence is when the poison is cutting of life towards the male organ. The bloodstream is coming polluted and it’s affecting the flow.

Men might shed the capability to preserve intimacy.
They might be able to start but then will not be able to finish.
Studies display the body without normal blood sugar levels is aging faster than 1 having a typical
sugar range.

Male impotence refers to the condition referred to also as Erectile Dysfunction, where for one cause or an additional, blood isn’t flowing to the penis properly, so that an erection can be achieved.

Causes for the disease range from 8 out of 12 of the top prescribed medicines of our day towards the result of mental disorder and physical deformity.

Countless medicines list impotence being a side effect of the treatment, and numerous nerve damaging problems can trigger ED. Depression, anxiety, and tobacco use are all stated leads to for impotence also.

Male impotence has numerous different leads to for that hydraulic problem that leads to the penis to not function correctly.

Smokers are 85% a lot more at risk to be in this group. The most shocking statistic nevertheless, is that only a mere 10% of those afflicted with Erectile dysfunction or a comparable concern seek remedy and help.

Impotence is a serious problem that impacts 25% of our population sixty five years of age and older. 5% of middle aged men and older today are afflicted by ED as well.

Following reading a couple of facts about the subject 1 hopes it is enough to consult your doctor or begin to make changes to stifle the results of the problem and better your high quality of existence immediately.

If it is just a few times then it ought to not be worried upon but if it’s frequent or enough to bring you worry and tension then you need
to appear into just what is causing it.

Impotence or Erectile Dysfunction happens to most men occasionally and for a range of reasons.

It’s interesting to note that most men and even doctors (is it simply because they’re
male?) believe that most impotence causes stem from the psychological aspects or way of life aspects of a man’s existence.

But it can also be fascinating to note that 60% of the males that do go to their physician with impotence problems end up being diagnosed with diabetes.

So my recommendation is that if you are having a problem with impotence that’s causing you concern
at least go to your doctor to obtain the actual reasons out from
the way.

It is also fascinating to note that 80% of men with impotence problems have a physical reason for getting them.

Not performing any exercising and being a couch potato.

That’s lots of causes to go via, but if you have or are performing any of them then the first thing you can do is stop performing them or go for your physician for assist.

Nevertheless, consuming alcohol or using any other intoxicants or adulterants can make it difficult for the human physique to accomplish an erection.

Alcohol and recreational medicines are known to be some of the most infamous libido enhancers for many years and years.

Having a glass of wine or two throughout social events may not be such a poor idea, however the rate to which the alcohol impacts your libido negatively or positively truly is dependent upon your body kind and size and weight.

For example, should you weigh 165 pounds or so you could consume as much as about a half of a bottle of wine prior to seeing a decrease in your erectile functioning,

Having a glass of wine or two throughout social events might not be this kind of a poor concept, however the rate to which the alcohol affects your libido negatively or positively truly depends on your body kind and size and weight.

Anything that affects a man’s testosterone in any way could possibly negatively have an effect on that man’s sexual intercourse generate inside a negative way. Whilst drugs and alcohol could lead to sexual interaction in numerous circumstances.

No matter what you select to drink or what you plan to accomplish following drinking takes place, positive decisions about drinking and drug usage are of utmost importance when considering your impotence.

Think about making existence modifications immediately should you ever hope to see complete improvement without the use of medication.

Nitric oxide and Impotence go hand in hand, simply because no guy can ever get an hard-on without it however the great news is you do not need to take guy made drugs to increase amounts, you can increase nitric oxide normally and safely.

These herbs will not just increase levels of nitric oxide, they will also increase amounts of the key male sexual intercourse hormone testosterone, enhance blood flow all close to the body, keep sperm wholesome and reduce stress and anxiety which can frequently trigger impotence.

You’ll discover all the above herbs in the best men’s sex pills and they may also contain L Arginine; this is not a herb but a natural amino acid which assists the physique create nitric oxide and if you increase levels by taking it being a supplement.

It’s been known as natures Viagra and with good cause – it assists you get a tougher erection and boosts sexual desire and is a supplement all males ought to consider, for much better sexual health.

You can get all of the above libido enhancers and a lot more, in the greatest organic hard erection pills which will assist you to remedy impotence safely and normally plus they will also increase your general degree of wellness at the same time.

1000s of males suffer with impotency, frequently turning to potentially risky medicines. That?s why the Blakoe Ring is revolutionary. It?s verified to become the safest and most efficient solution to these problems.

This increases blood flow towards the sexual organs, helping the body to regain its natural capabilities. It also improves problems such as: low sex generate, reduced sperm count, underdeveloped genitals, and premature ejaculation.

Male impotence remedies are an extremely well-liked subject right now simply because many males are treating their erectile dysfunction naturally.

Because male impotence is triggered by a lack of blood circulation below the belt, these remedies might assist you to by tomorrow.

Begin your physical exercise program today! Remember the rush after a good function out? It’s proven that exercising has 1000s of advantages such as: boosting flow, flushing cholesterol, reducing tension and increasing endorphins happy chemicals. Start at 30 minutes a day and work as much as an hour.

Practice breathing methods like only breathing through your nose for five minutes. You can do this at your work desk and you will be decreasing stress and boosting flow amounts.

Begin your physical exercise program these days! Remember the rush following a great function out? It’s proven that exercising has thousands of benefits including: boosting flow, flushing cholesterol, decreasing stress and growing endorphins happy chemicals.

You are one of the couple of but you will find thousands of males who are afflicted by young male impotence. Don’t be discouraged because there are numerous methods to increase flow downstairs and increase your libido.

Erectile dysfunctions are generally a physical issue like poor circulation. There are a range of leads to for ED but most individuals are afflicted by this typical illness simply because of poor circulation.

Lower flow amounts could be caused by too much stress, a bad eating habits, bad way of life choices or even a lack of vitamins or nutrients.

Vitamin therapy can also be well-liked with this remedy for erectile dysfunctions. Research is showing a strong correlation that most males who are afflicted by this illness are deficient in vitamin A.

You will find many points you should know about your eating habits however the greatest rule of thumb is to maintain your diet easy and fresh. Try to prevent fattening foods which are fried.

Prevent certain things like alcohol, cigarettes and caffeine. All of these listed items are drugs which alter the physique in exact same shape or form. Research does show that avoiding these can assist increase circulation downstairs.

There are also lots of herbs which have been shown to have a good effect. For instance, horny goat weed is a common and effective herb that is shown to become a testosterone booster, aphrodisiac and also tension reducer.

Deep breathes Did you know that merely trying deep breath exercises every day can help increase flow amounts and reverse impotence? Start with big exhales and inhales for 5 minutes and do this three times every day.

All males over the age of 30 encounter impotence as least as soon as within their lifetime. Estimating the numbers is difficult simply because less than 2 males in 10 seek treatment for impotence difficulties. The conclusion is impotence is really a really common problem in males.

The big issue is it seems that for a large quantity of males, their capability to obtain an erection and have sexual intercourse is viewed as an integral component of their masculinity and potency and could be debilitating to his mental health.

Very first reaction of the man dealing with impotence is to make excuses or prevent sexual circumstances with his partner in an effort to forget about the problem. This tendency can frequently leave the partner feeling unloved, unattractive and unwanted.

Encountering this issue, males must think very first that this really is a very common male issue. He is neither alone nor unusual. You will find over hundred million partners of impotent men.

consequence, the man’s failure to communicate his condition might contribute to frustration, stress or depressive disorders in his partner, or even cause relation failure.

Couples who can talk openly about this problem have an excellent benefit. Sharing fears and worries is a very first step toward feeling better.

Woman’s emotions regarding the impotence of her partner can be complex as nicely. But she should not overlook that the male partner is going via similar powerful emotions.

Woman’s help and understanding of situation is very essential. In a spirit of friendly cooperation, she must provide her support in solving partner’s problem going together to see a doctor.

Male impotence is a problem whereby a guy isn’t capable of sexually pleasing the woman in his existence. This might be because of a weak erection more popularly known as erectile dysfunction.

Whenever you believe about it for a whilst you slowly realise that a large portion from the male population prides itself for being effectively dangerous in bed. And whilst some of those allegations might be true a big whole lot of them are false.

These substances greatly reduce the circulation of blood around the body simply because of the deposition of fats in major arteries.

The moment blood pressure decreases the veins in the penis are starved from the rapid flow they need to erect a penis that is stiff enough for successful sexual penetration.

Substance abuse has been cited as a trigger of erectile dysfunction. Alcohol; cigarettes; and hard medicines like cocaine should be gotten rid of right way.

Not so lengthy ago it was discovered that impotence and diabetes go hand in hand. This means reducing ones intake of foods with lots of sugar is one way of fighting impotence.

When you have diabetes and continue to abuse sugar your diabetic issues will worsen and so will impotence have an effect on you a lot more adversely. Should you don’t know if you have diabetic issues it would be a good tie to know so that you simply head straight into insulin treatment.

The next time you’ve sexual intercourse be certain to become calm and confident. Sometimes sex associated problems are attributed to anxiety and nervousness. Perhaps you’re too embarrassed about showing a certain component of your physique you think she will laugh at.

Forget about everything and try to possess fun. A carefree attitude is essential when it comes to sex.

Viagra is really a pharmaceutical drug that’s utilized by a lot of men to trigger and maintain a stiff erection. For some men this works really nicely but you will find people who do not have that much success with it.

But occasionally the problem of obtaining a difficult hard-on stems from getting as well a lot intercourse within a short period of time. To have the ability to obtain a quick and difficult hard-on you should have the space of about 3 days until you’ve sex again.

Impotence is happen when a guy can not accomplish or maintain an hard-on inside sufficient time to please himself and obviously, his partner. Impotence is frequently only though of affecting older men, nevertheless it’s quite common location in youthful men as well.

Impotence in youthful males can be very stressful and it can also become a downward spiral due to the fact that one bad experience can lead to a large amount of self doubt and anxiety.

Impotence in young males can trigger further difficulties with low self esteem and other existence issues in themselves as nicely as their relationships. But, possibly simply because impotence is not some thing which can be openly discussed.

Most males will develop impotence at some point within their life. But in the majority of cases it is a 1 off occurrence, not a lengthy term one. When impotence occurs over the lengthy term it’s deemed a problem and this is when professional advice and testing is required.

The choices for impotence treatment in youthful men are usually not to take powerful prescription medicines. An alternative is herbal remedy as these are gentler and do not trigger side effects.

A youthful male can also be highly unlikely to wish to consider Viagra as they think about becoming an older mans impotence drug.

The following option is to have a wholesome lifestyle. Avoid higher consumption of alcohol and drugs. Physical exercise frequently to make your blood circulation smooth. Consider a wholesome and balance diet.

Impotence in youthful men usually disappears as they gain experience and confidence in sexual situations and is very rarely caused by a serious physical problem. In the same, practicing a healthy way of life is better option then to remedy the impotence later.

Exercise has literally hundreds of benefits but one particular one is that it will boost flow amounts towards the penile regions. It has also been shown to decrease stress.

Name (required)
E-mail (required - never shown publicly)
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.