Set up a search-box (textfield/html) to search content within a specific course?

Set up a search-box (textfield/html) to search content within a specific course?

by Stefan Joller -
Number of replies: 4

I'm trying to implement a search-box into a moolde course with a lot of content. Of course you can use the global search and set a filter to the specific course. But I'd rather place a search-box directly in this course for better UX.

Can anyone help setting up such a search-box (eg. using textfield/html)? Maybe even post a html code snippet?
I'm looking basically for global search box with a predefined filter to a certain course.

I know how to set a global search box within a course using textfield/html - what I haven't achieved so far, is presetting a filter to the course within the global search.
Is there a way to preset filters directly in the URL (global search: https://xxxx.com/search/index.php)?

Thanks for your help!

Average of ratings: Useful (1)
In reply to Stefan Joller

Re: Set up a search-box (textfield/html) to search content within a specific course?

by Stefan Joller -

We found a solution for this problem - you can add a label with a search box, that searches only within a certain course, using the follwoing html code:


<form class="search-input-form expanded" action="https://YOURMOODLEURL/search/index.php"><label for="id_q_XXXXX" class="accesshide">Search</label><input type="text" filter="course: coursename" name="q" placeholder="Search" size="13" tabindex="-1" id="id_q_XXXXX"
        class="form-control">
    <input type="hidden" name="context" value="2"> <input type="hidden" name="courseids" value="insert id-number of course">

</form>

Average of ratings: Useful (2)
In reply to Stefan Joller

Re: Set up a search-box (textfield/html) to search content within a specific course?

by Eoin Campbell -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
This is a great idea, especially for courses with a lot of material. I have published a Generico filter that you can use to insert this HTML fragment into any course, see Re: Generico Showcase (in-course search box) for details.
Average of ratings: Useful (3)
In reply to Eoin Campbell

Re: Set up a search-box (textfield/html) to search content within a specific course?

by Luis de Vasconcelos -
Thanks. This looks very interesting! smile
In reply to Stefan Joller

Re: Set up a search-box (textfield/html) to search content within a specific course?

by Dennis Verdonck -
I tried to put this code in the HTML of a Label, but it doens't work.
what does I have to fill in for the "XXXXX"?

Thanks !