rejetto forum

HELP: Search only for folders (without use of Javascript)

0 Members and 1 Guest are viewing this topic.

Offline Kremlin

  • Tireless poster
  • ****
    • Posts: 137
    • View Profile
So.. i need some help on making the search default for only folders without the use of Javascript. The idea is to basically type your search in as input and when pressing the search button it will redirect you to a link like this:

http://localhost/?folders-filter=*{.$search-data.}*&recursive&files-filter=\

Can anyone write the code for this? A good starting point might be the ToG search form..

<form action="/" name="simpleSearch" method="get">
         <input class="formInput" type="text" name="search" size="13" maxlength="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
         <input type="submit" value="Go"/>
</form>

ps. from what i think, it needs to add an onclick value to the button "Go", unfortunately i can't figure out how it should be written
« Last Edit: February 06, 2009, 09:18:38 AM by Kremlin »


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1935
    • View Profile
    • RAWR-Designs
Can't believe no one has helped you yet. Might be cause there is no easy way to do this without javascript.

If you look at the advanced search function I have made in javascript, it basically builds a valid link for HFS to use. Without building a link I do not think it is possible with just a form. Especially the insertion of stars on either side of query, forgotten what they do, but I know its important.

Code: [Select]
/* RAWR Search Form. */
function searchQuery() {
 //Form to use.
frm = document.searchForm;
if(frm.query.value.length < 3) {
// Alert user if query is less than 3 characters, take the load off HFS.
alert(lv_searchAlert);
} else {
// Determine what choices are made in the form.
frm.recursive.checked ? recursive ="&recursive" : recursive ="";
for(x=0; x<frm.choice.length; x++) {
if(frm.choice[x].checked ==1) {
if(frm.choice[x].value =="file") {
searchMode ="?files-filter=";
filter="&folders-filter=%5C";
} else if(frm.choice[x].value =="folder") {
searchMode ="?folders-filter=";
filter="&files-filter=%5C";
} else {
searchMode ="?filter=";
filter="";
}
}
}
for(c=0; c<frm.root.length; c++) {
if(frm.root[c].checked ==1) {
frm.root[c].value =="current" ? searchFrom ="http://"+serverHost+serverFolder : searchFrom ="http://"+serverHost;
}
}
//Build a link and submit values to HFS.
document.location.href = searchFrom+searchMode+"*"+frm.query.value+"*"+recursive+filter;
}
}
« Last Edit: February 06, 2009, 12:47:52 PM by That_Stevens_Guy »


Offline Kremlin

  • Tireless poster
  • ****
    • Posts: 137
    • View Profile
This is what i've gotten so far (doesn't work though dunno why)

The javascript code from ToG modified for only folders:

Code: [Select]
function searchQuery() {
frm = document.searchForm;
if(frm.query.value.length < 3) {
alert(lv_searchAlert);
} else {
for(c=0; c<frm.root.length; c++) {
if(frm.root[c].checked ==1) {
frm.root[c].value =="current" ? searchFrom ="http://"+serverHost+serverFolder : searchFrom ="http://"+serverHost;
}
}
document.location.href = searchFrom+"?folders-filter="+"*"+frm.query.value+"*"+"&recursive"+"&files-filter=\";
}
}

And then in the template:

Code: [Select]
<form action="/" name="simpleSearch" method="get">
<input class="formInput" type="text" name="search" size="13" max-lengh="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
<input class="search" type="submit" size="13" value="Go" onclick="searchQuery()"/>
</form>

If anyone knows why this doesn't work please reply and help  ;)


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1935
    • View Profile
    • RAWR-Designs
Forum seems lazy, here is my simplest solution, for use with our templates. Sorry, I cant work it out just now without javascript, maybe the macro masters can have a try, but it wont be as simple as this.

Append this to main.js:
Code: [Select]
function folderQuery() {
    frm = document.folderForm;
    if(frm.query.value.length < 3) {
        alert(lv_searchAlert);
    } else {
        document.location.href = "http://"+serverHost+"?folders-filter=*"+frm.query.value+"*&recursive&files-filter=%5C";
    }
}

Put this in place of the advanced search link and the simple search form:
Code: [Select]
<form action="javascript:folderQuery();" name="folderForm" method="get">
    <input class="formInput" type="text" name="query" size="13" maxlength="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
    <input type="submit" value="Go"/>
</form>
« Last Edit: February 07, 2009, 06:04:54 AM by That_Stevens_Guy »



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
good to see you got it.
javascript is needed to get the ** part.
the rest can be done even without javascript

<form action='/'>
<input type='hidden' name='recursive' value='1'>
<input type='hidden' name='files-filter' value='\'>
<input name='folders-filter'>
<input type='submit'>
</form>


(untested)