View Full Version : Refine search, but not based on path

01-28-2005, 06:10 AM
In reply to: http://www.phpdig.net/forum/showthread.php?t=1042&highlight=refine

This is a very basic hack to allow the user to refine her/his search by selecting a radio button below the search-box.

First of all let me say that I'm very new to phpdig and I'm sure there are better ways to achieve what I'm trying to do here. Please let me know :)

THE modded FILE: libs/function_phpdig_form.php

Around line 197... I have put this (the head of the form):
$result['form_head'] = "
function radioValue(radioButton) {
for (var x = 0; x <= radioButton.length-1; x++)
if (radioButton[x].checked == true) return radioButton[x].value;
return radioButton.value;
<form action='$result_page' method='post' name='soegeform' onsubmit=\"document.soegeform.query_string.value=document.soegeform.query_string.value + ' ' + radioValue(refine_search)\";>
<input type='hidden' name='site' value='$site'/>
<input type='hidden' name='path' value='".htmlspecialchars($path,ENT_QUOTES)."'/>
<input type='hidden' name='template_demo' value='$template_demo'/>
<input type='hidden' name='result_page' value='$result_page'/>

And in the footer of the form (approx. line 214 if you have pasted the other stuff):
$result['form_foot'] = "
<input type='radio' name='refine_search' value='anatomi' checked>Alt
<input type='radio' name='refine_search' value='soeg_emner'>Emner
<input type='radio' name='refine_search' value='placering=main'>Præparater
<input type='radio' name='refine_search' value='soeg_oevrige'>Øvrige sider

In order for it to work you have to place a keyword on every page that is corresponds to the value of a radio button. My keywords are:
placering=main AND
...I will paste them into my documents before I do my digging...

It works like this: When the user has selected a radio button and pressed the submit-button the JavaScript on the submit-button pastes the radio button-value into the search-box along whit what the user put (if anything). This is (naturally) done before the values are passed to the search-script (action='$result_page').

Maybe this can inspire someone? Maybe someone can achieve the same in a more clever way?

God I hate JavaScript :)