고수님들 도와 주세요. ㅠㅠ
본문
제가 만든 메인 페이지에 검색 할 수 있는 검색폼을 달고자 하는데요. 검색폼만 달아서 검색을 할 수 있는 방법은 소스 같은거나 아님 달 수 있는 방법은 없나요? 도와주세요 고수님들...... 그느보드 5입니다.
답변 1
아래 코드와 같이 head.php 파일에 있는 검색 부분만 가져와서 넣으시면 됩니다.
단, 현재 아래 코드의 파일은 루트에 파일이 있을 경우에 정상 동작하고요.
<?php
include_once('./_common.php');
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<fieldset id="hd_sch">
<legend>사이트 내 전체검색</legend>
<form name="fsearchbox" method="get" action="<?php echo G5_BBS_URL ?>/search.php" onsubmit="return fsearchbox_submit(this);">
<input type="hidden" name="sfl" value="wr_subject||wr_content">
<input type="hidden" name="sop" value="and">
<label for="sch_stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx" id="sch_stx" maxlength="20">
<input type="submit" id="sch_submit" value="검색">
</form>
<script>
function fsearchbox_submit(f)
{
if (f.stx.value.length < 2) {
alert("검색어는 두글자 이상 입력하십시오.");
f.stx.select();
f.stx.focus();
return false;
}
// 검색에 많은 부하가 걸리는 경우 이 주석을 제거하세요.
var cnt = 0;
for (var i=0; i<f.stx.value.length; i++) {
if (f.stx.value.charAt(i) == ' ')
cnt++;
}
if (cnt > 1) {
alert("빠른 검색을 위하여 검색어에 공백은 한개만 입력할 수 있습니다.");
f.stx.select();
f.stx.focus();
return false;
}
return true;
}
</script>
</fieldset>
</body>
</html>
답변을 작성하시기 전에 로그인 해주세요.