Forums

Making a xhtml valid searchform using a php if/else statement (3 posts)

  1. Paragamer09
    Member
    Posted 9 months ago #

    I'm trying to make a xhtml valid search form using an if/else php statement. I want the searchform to say 'Search...' before you type into it, but as soon as you type, it needs to show what you are typing.

    This is the code I have so far:

    value=" <?php
    if
      echo "Search";
    else
      echo "<?php the_search_query(); ?>";
    ?>

    I want the if statement to be something along the lines of if the search query is blank, however I have no idea how to write this in php.

    Any help will be greatly appreciated!

  2. chaoskaizer
    Member
    Posted 9 months ago #

    try

    ...
    value="<?php echo (( '' != get_search_query() ) ? get_search_query() : __('Search') ); ?>"
    ...
  3. warfman99
    Member
    Posted 8 months ago #

    There is a plugin that might do it for you. Not sure if this is exactly what you're going for, but I've used this plugin, and it works well and is very easy to setup.

    http://labs.jcow.com/plugins/enhanced-search-box/

Reply

You must log in to post.

About this Topic

Tags

No tags yet.