homepage Welcome to WebmasterWorld Guest from 54.205.188.59
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

This 43 message thread spans 2 pages: < < 43 ( 1 [2]     
Functional search box
ghid




msg:4595063
 4:04 pm on Jul 21, 2013 (gmt 0)

Hi,

I have some knowledge in HTML,PHP and CSS, and I want to implement a functional
search box on a syte and I don't know where to start.

I want that the search to be made whithin my site content.

Please help me to do that.

Thank you in advance.

 

londrum




msg:4606812
 6:50 pm on Sep 2, 2013 (gmt 0)

don't include search.php, because thats the search results page. all you need to have on your clothes page is a search box. the search box will then redirect the user to search.php automatically, where the results will be displayed.

look in the templates folder. you should have something called "search_form.html".
that is what you need to include on your clothes page. the search box is just normal html. so it shouldn't cause you any problems with php errors
in fact, you don't even really need to include it. you could simply copy the code and paste it straight into your clothes page.

give that a go

(if you've been fiddling with the paths on commonfuncs, maybe you'll have to change them back)

ghid




msg:4607594
 5:16 pm on Sep 5, 2013 (gmt 0)

I had found search_form.html file in the template folder. I had copied it's content in my index page, nothing happened. Also I had included with include function and nothing again.

I don't know how to manage this problem. Please give me some ideeas.

londrum




msg:4607604
 5:40 pm on Sep 5, 2013 (gmt 0)

that search form template should just be normal html -- a search form. if you paste it into your index page then you should be able to see something

post the code here so we can see, because i've amended all of my templates now.

it should be something along the lines of this...

<form action="blah" method=get><fieldset><input type=text name=query size=19 value="<?php print quote_replace($query);?>"><label for=query><input type="submit" class=submit value="Search" ></label><input type=hidden class=hd name=search value=1></fieldset></form>
ghid




msg:4608051
 8:40 am on Sep 7, 2013 (gmt 0)

I will put and the index page code:

The index page .php:



<!-- *** TURNS ON PHP ERRORS *** -->

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

?>


<!-- ****************************** -->




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<link rel="stylesheet" type="text/css" href="clothes.css" >


</head>


<body>


<div class="big">


<div id="antet">


<!-- **************** *** ********************************* -->

<div style="float:right;margin:0px 10px;"> <a href="#" style="text-decoration:none"> <img

src="clothespicture/shopping_chart.jpg" width="20"

style="padding-right:5px;margin-top:4px;border:none;"> <span style="vertical-align:top">

cucurigu </span></a> </div>


<!-- **************** ***** ********************************* -->


<div style="float:left"> <span id="firma"> AB </span> </div><div

style="float:left;padding-top:16px;background-color:red">AB FASHION </p> </div>


</div> <!-- end antet -->


<div id="top">

<ul id="menu">


<li>

<a href="#"> HOME </a>

<ul>

<li> <a href="#"> abc </a> </li>
<li> <a href="#"> abc </a> </li>

</ul>

</li>

<li>

<a href="#"> COLLECTIONS </a>

</li>

<li>

<a href="#"> BLOG </a>

</li>


<li>

<a href="#"> ABOUT US </a>

</li>



</ul>

<div style="float:right"> <p> abc </p> </div>

</div> <!-- end top -->



<div id="content">

<p> asd am avut un acvariu de pesti, de ciclide, mbune albastre, galbene si un oscar. Acvariu de

ciclide trebuie sa fie foarte mare</p>





</div> <!-- end content -->



<!-- ************ Here I putted the template code ************** -->


<div style="background-color:red"> <!-- DIV SEARCH -->




<table cellpadding="5" cellspacing="1" class="searchBox">
<tr>
<td align="center">

<form action="search.php" method="get">

<table><tr><td>
<div align="left">
<input type="text" name="query" id="query" size="40" value="<?php print

quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off"

delay="1500">
</div>
<td>
<input type="submit" value="<?php print $sph_messages['Search']?>">
</td></tr></table>


<?php if ($adv==1 || $advanced_search==1) {
?>
<table width = "100%">
<tr>
<td width="40%"><input type="radio" name="type" value="and" <?php print

$type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td>
<td><input type="radio" name="type" value="or" <?php print

$_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr>
<tr>
<td><input type="radio" name="type" value="phrase" <?php print

$_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td>
<td><?php print $sph_messages['show']?>
<select name='results'>
<option <?php if ($results_per_page==10) echo "selected";?>>10</option>
<option <?php if ($results_per_page==20) echo

"selected";?>>20</option>
<option <?php if ($results_per_page==50) echo "selected";?>>50</option>
<option <?php if ($results_per_page==100) echo "selected";?>>100</option>
</select>

<?php print $sph_messages['resultsPerPage']?>
</td>
</tr>
</table>
<?php }?>



<?php if ($catid<>0){?>
<center><b><?php print $sph_messages['Search']?></b>: <input type="radio"

name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?>

"<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1"

checked><?php print $sph_messages['All sites']?></center>
<?php }?>
<input type="hidden" name="search" value="1">
</form>
<?php if ($has_categories && $search==1 && $show_categories){?>
<a href="search.php"><?php print $sph_messages['Categories']?></a>
<?php }?>
</td>

</tr>
</table>



</div> <!-- END SEARCH -->



</div> <!-- end big -->





</body>




</html>





here is the .css file:



*{

margin: 0px;
padding:0px;

}


html,body {

background-color:pink

}


.big {

margin: 10% 20% 20% 20%;
background-color:FFFFF;


}


#menu {

list-style:none;
height:15px;
/*border-style:solid; */ /* in caz ca se doreste ca border-ul sa contina doar lista ul */
display:inline-block; /* ca sa faca un fel de container, sa nu iasa elementele din
border */
/*margin-bottom:0;*/
/* display:inline-block; */
/* padding-bottom:20px; */ /* sau ii putem da acestei clase, respectiv listei ul la care ii asociem
aceasta clasa width:Xpx; height:Ypx; se pare ca listele nu sunt
continute in border */



}

#menu li {
position:relative; /* se pune pentru ca lista dropdown sa fie aliniata vertical cu
elementele parinte */
margin-left:10px;
float:left;

}


#menu ul li {

float:none; /* ca sa anuleze float:left-ul precizat in #menu li, care s-ar fi rasfrant
si asupra acestor elemente */
list-style:none;
margin-left:0;

}


#menu ul { /* ascunde lista drop down */

position:absolute;
left:-9999px;
margin:0;

}


#menu li a {

padding: 0px 4px 0px 4px;

}





#menu li:hover ul { /* afisaza link-urile dropdown */

left:0;

}


#menu a:hover{ /* culoarea backgroundului elementului in momentul in care
treci cu mouse-ul peste ele */

background-color:white;
color:black;

}






#menu ul li a{ /* padding-ul pentru elementele din dropdown */

background-color:blue;
padding: 0px 20px;


}

#menu a { /* scoate underlineurile din toate linkurile din clasa menu */

text-decoration:none;

}




#content {

background-color:green;

}


#top {

background-color:#FFFFFF; /* la codurile astea trebuie neaparat pus in fata # */
border-style:dotted;
border-width:1.5px;
border-right-color:#ffffff;
border-left-color:#ffffff;

}

#antet {

background-color:#ffffff;
height:90px;
padding-top:10px;

}


#antet a:hover {


color:red;
padding:0px;


}



a {

padding:0px;

}

#firma {
font-size:250%;
background-color:black;
color:white;
margin: 0px 10px;

}




And here is the template search_form.html code:




<center>
<table cellpadding="5" cellspacing="1" class="searchBox">
<tr>
<td align="center">

<form action="search.php" method="get">

<table><tr><td>
<div align="left">
<input type="text" name="query" id="query" size="40" value="<?php print quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500">
</div>
<td>
<input type="submit" value="<?php print $sph_messages['Search']?>">
</td></tr></table>


<?php if ($adv==1 || $advanced_search==1) {
?>
<table width = "100%">
<tr>
<td width="40%"><input type="radio" name="type" value="and" <?php print $type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td>
<td><input type="radio" name="type" value="or" <?php print $_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr>
<tr>
<td><input type="radio" name="type" value="phrase" <?php print $_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td>
<td><?php print $sph_messages['show']?>
<select name='results'>
<option <?php if ($results_per_page==10) echo "selected";?>>10</option>
<option <?php if ($results_per_page==20) echo "selected";?>>20</option>
<option <?php if ($results_per_page==50) echo "selected";?>>50</option>
<option <?php if ($results_per_page==100) echo "selected";?>>100</option>
</select>

<?php print $sph_messages['resultsPerPage']?>
</td>
</tr>
</table>
<?php }?>



<?php if ($catid<>0){?>
<center><b><?php print $sph_messages['Search']?></b>: <input type="radio" name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?> "<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1" checked><?php print $sph_messages['All sites']?></center>
<?php }?>
<input type="hidden" name="search" value="1">
</form>
<?php if ($has_categories && $search==1 && $show_categories){?>
<a href="search.php"><?php print $sph_messages['Categories']?></a>
<?php }?>
</td>

</tr>
</table>
</center>




Thank you.

ghid




msg:4608074
 1:41 pm on Sep 7, 2013 (gmt 0)

I am getting to resolve it.

I had putted in my index page a simple form:

<form action="./sphider/search.php" method="get" >
<input type="text" name="query" >
<input type="submit">
</form>

When I complete the search form and I press the submit button it redirects me to the search page, where appears the sphider search box with my anterior typed text and I have to press search again.

How I do like after I complet the search form and I press submit from my index page, the string characters to be directly processed and the result to be directly displayed without pressing search button again?

londrum




msg:4608079
 2:28 pm on Sep 7, 2013 (gmt 0)

the results should be coming up straight away. after you press search again, do you get any results?

dumb question... have you spidered your site yet? if you haven't spidered your site then you won't get anything up
you need to go into the admin section, click "add site", and do all that stuff. you should have an /admin directory with an admin.php file in it.
visit the /sphider/admin/admin.php file in your browser

ghid




msg:4608085
 2:55 pm on Sep 7, 2013 (gmt 0)

Yes, when I press search again I get results.

But it is a problem because I have to press search twice to get the result, I don't know how to solve this.

The string character doesn't go directly to be searched, it is just passed to the search.php form, and then I have to press search again.

londrum




msg:4608097
 4:15 pm on Sep 7, 2013 (gmt 0)

you have this bit in your template

<input type="text" name="query" id="query" size="40" value="<?php print

quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off"

delay="1500">

have you got all of that on one line? maybe it won't make a difference, but it should all be on one line. it looks like you might have it on three lines from the way you pasted it.
the search box code further down in your post looks different

ghid




msg:4608105
 4:49 pm on Sep 7, 2013 (gmt 0)

I don't think that have signifiance. I write the code in notepad, the number of lines depends of the width of the opened page.

londrum




msg:4608111
 5:23 pm on Sep 7, 2013 (gmt 0)

sure, but it will make a difference if you've pressed 'return' after
<?php print, for example -- giving the next bit a new line number. <?php print quote_replace($query);?> all needs to be on the same line number.
otherwise i haven't got a clue

ghid




msg:4608253
 7:48 am on Sep 8, 2013 (gmt 0)

Yes, but I errases the code copyed from the search_form.php, and replaced with:



<form action="./sphider/search.php" method="get" >
<input type="text" name="query" >
<input type="submit">
</form>



Here is the problem. How do I transfer the content typed in that form so that when I press submit the searched content to appear. Because now, it appears to me the search page with the content text in search box, and I have to press search again.
Can you help me with this? Because the code in the search.php page is over my knowledge, and I don't succed to solve that.

londrum




msg:4608268
 9:02 am on Sep 8, 2013 (gmt 0)

i haven't got a clue mate, i think you've fiddled the whole thing to death. it shouldn't be this hard -- it is supposed to work straight out of the box. why don't you just download a fresh copy and restart from the beginning?

just use the code as it is, don't change anything this time, because it does work

ghid




msg:4608488
 3:11 pm on Sep 9, 2013 (gmt 0)

I didn't fiddled at all. I found on a forum a line that resolved my problem with pressing submit twice.
This is the line:

<input type="hidden" name="search" value="1">

I don't know what does this value parameter, I wish to but I don't, finally it's working.

Thank you for your support.

This 43 message thread spans 2 pages: < < 43 ( 1 [2]
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved