Moodle search box

For one reason or another, I’ve been very much involved in setting up Moodle based sites lately. We have a project rolling out eLearning platforms to most Local Authorities in the East of England, and the foundation for these is Moodle 2.1

In the way Moodle is configured a search tool only really exists for courses if you add a list of courses to the front page of the site. It is included as part of that, so I was hunting through the code looking for ways to put the search box in other places.

It turns out to be quite simple. All you have to do is add a new HTML block to the menu bar and type in the following:

<form action="http://www.sitedomainname/search.php" method="get">Search Courses: <input type="text" name="search" size="12" alt="Search Courses" /> <input type="submit" value="go" /></form>

This creates the search box, passes the entered string to the built in Moodle searh scripts and returns the result to the main part of the page.

Very easy, very good to have. Of course, you could also add this to individual pages, courses and whatever, but with a block in the menu you can specify whether it appears only on the front page, or throughout the site. Moodle can’t get much simpler… 🙂

2 thoughts on “Moodle search box

  • 2 April, 2012 at 5:57 pm
    Permalink

    I followed the directions you have on your blog and go so far as to make the search box, but when I actually attempt to search for something, it comes back with a 404 /search.php not found.

    How do I actually make the search.php file if one doesn’t exist?
    thanks.

  • 2 April, 2012 at 9:30 pm
    Permalink

    Hi AJ – the code snippet above is a simplified piece of code – you need to adjust it to suit your site.

    The best thing I can suggest is to open up your moodle site, click on a course category as a site admin and look for the search box on that page. Click in it and then use a decent browser (Chrome or Safari would do) and right click to inspect the element (not sure if this can be done on a PC… it happens on a Mac though). In the next view you’ll see the code that builds the search form… copy this directly into your HTML block and it should work.

    As an example, here’s the code I use from one of my sites:


    <form id="coursesearch" action="http://www.sitedomainname/courses/course/search.php" method="get"><fieldset class="coursesearchbox invisiblefieldset"><label for="coursesearchbox">Search courses: </label><input type="text" id="coursesearchbox" size="30" name="search" value=""><input type="submit" value="Go"></fieldset></form>

    Note the use of ‘courses/course/’ in the search domain.

Comments are closed.