PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Mod Submissions (http://www.phpdig.net/forum/forumdisplay.php?f=24)
-   -   Refine search, but not based on path (http://www.phpdig.net/forum/showthread.php?t=1786)

kristian 01-28-2005 06:10 AM

Refine search, but not based on path
 
In reply to: http://www.phpdig.net/forum/showthre...ghlight=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):
Code:

    $result['form_head'] = "
  <script>
  function radioValue(radioButton) {
        for (var x = 0; x <= radioButton.length-1; x++)
        {
                if (radioButton[x].checked == true) return radioButton[x].value;
        }
                return radioButton.value;
        }
  </script>
  <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):
Code:

$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
  </form>";

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:
anatomi
soeg_emner
placering=main AND
soeg_oevrige
...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 :)


All times are GMT -8. The time now is 05:14 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.