TinyPortal

Development => Support => Topic started by: SN on March 03, 2010, 09:47:36 AM

Title: Search Code?
Post by: SN on March 03, 2010, 09:47:36 AM
Im trying to create my own custom search bar and button, similar to the one on the top of this theme but in a block.

I want to put it in a Top Block so its going across the top of my page.

What is the Code for a php search bar and button?

I am using TP beta4 and 1.1.11... but im not going to use it for that version i want it to work when i upgrade to 2.0
Title: Re: Search Code?
Post by: Mick on March 03, 2010, 10:15:22 AM
This is the code form index.template.php

echo'
<form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" /></div>';



...but when trying to save it to a php block, it takes me to the results page instead.
Title: Re: Search Code?
Post by: SN on March 03, 2010, 11:38:36 AM
Oh didnt know u was a memeber here also.

Yeah i have tried it also it dose the same for me.

What i am trying to do is have the search bar in a HTML table

or a PHP table with the search bar in, but i dont know how to code in PHP


here is what i am trying <table background= "http://spursnetwork.com/images/bar-bg.png" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="1%"><img src="http://spursnetwork.com/images/left-end.png" width="9" height="36" align="left"></td>
    <td width="44%"><?php echo 
</div>
<div class="news normaltext">
<form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" /> ?>
</td>
    <td width="10%">&nbsp;</td>
    <td width="44%"><!-- AddThis Button BEGIN -->
      <div align="right"><a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4b0e9d1854bb7905"><img src="http://s7.addthis.com/static/btn/v2/lg-bookmark-en.gif" alt="Bookmark and Share" style="border: 0pt none;" height="16" width="125"></a><br>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4b0e9d1854bb7905"></script>
      </div>
    <!-- AddThis Button END --></td>
    <td width="1%"><img src="http://spursnetwork.com/images/right-end.png" width="9" height="36" align="right"></td>
  </tr>
</table>


but when i try the search results i get a server error

im trying to get something similar to this in a top block
Title: Re: Search Code?
Post by: IchBin on March 03, 2010, 02:26:39 PM
You can't do PHP like that in a block when you open PHP tags. You have to close and open them as if you are putting it inside another  php block. Try this code:
?>
<table background= "http://spursnetwork.com/images/bar-bg.png" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="1%"><img src="http://spursnetwork.com/images/left-end.png" width="9" height="36" align="left"></td>
    <td width="44%"><?php echo 
</div>
<div class="news normaltext">
<form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" /> ?>
</td>
    <td width="10%">&nbsp;</td>
    <td width="44%"><!-- AddThis Button BEGIN -->
      <div align="right"><a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4b0e9d1854bb7905"><img src="http://s7.addthis.com/static/btn/v2/lg-bookmark-en.gif" alt="Bookmark and Share" style="border: 0pt none;" height="16" width="125"></a><br>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4b0e9d1854bb7905"></script>
      </div>
    <!-- AddThis Button END --></td>
    <td width="1%"><img src="http://spursnetwork.com/images/right-end.png" width="9" height="36" align="right"></td>
  </tr>
</table>
<?php


However, it looks like your search form is not complete. You're missing some other code I'm sure as there is no ending </form> tag.
Title: Re: Search Code?
Post by: Crip on March 03, 2010, 02:45:21 PM
interesting bit of code there ..
Title: Re: Search Code?
Post by: SN on March 03, 2010, 03:29:22 PM
Thanks for that Inchbin, it working in a php Block now. but the search isn't. I think your right there's something wrong with the search form, but i have no idea how to fix it.

I just copied that code from index.template.php on default theme on rc2 where it has the search bar on the right hand side.

the error i get when i try to search is this
QuoteNot Found

The requested URL /forums/', $scripturl, ' was not found on this server.

any idea how i can fix it or get the correct form
Title: Re: Search Code?
Post by: Crip on March 03, 2010, 03:38:29 PM
might need that >> global $context, $settings, bit added ?
Title: Re: Search Code?
Post by: SN on March 03, 2010, 03:44:06 PM
AH i got it working.

i added the action Link into action="',

now its

?>
<table background="http://spursnetwork.com/images/bar-bg.png" border="0" cellpadding="0" cellspacing="0" width="100%">
  <tbody><tr>
    <td width="1%"><img src="http://spursnetwork.com/images/left-end.png" align="left" height="36" width="9"></td>
    <td width="44%">
         
</div>
<div class="news normaltext">
<form id="search_form" style="margin: 0;" action="http://spursnetwork.com/forums/index.php?action=search2"', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />
<input type="submit" name="submit" value="Search" class="button_submit" />
<input type="hidden" name="advanced" value="0" /></td><td width="10%"> </td>
    <td width="44%"><!-- AddThis Button BEGIN -->
      <div align="right"><a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&pub=xa-4b0e9d1854bb7905"><img src="http://s7.addthis.com/static/btn/v2/lg-bookmark-en.gif" alt="Bookmark and Share" style="border: 0pt none;" height="16" width="125"></a><br>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4b0e9d1854bb7905"></script>
     
    <!-- AddThis Button END --></td>
    <td width="1%"><img src="http://spursnetwork.com/images/right-end.png" align="right" height="36" width="9"></td>
 
</tr></tbody>
</table>
Title: Re: Search Code?
Post by: IchBin on March 03, 2010, 04:03:22 PM
You didn't need to change the action. You just needed to add this line at the top of your block before the ?> tag.

global $context, $scripturl;

I'd remove the hard code url you put in there and add the line above to your code. Otherwise you'll be getting errors in your log too.
Title: Re: Search Code?
Post by: SN on March 03, 2010, 05:15:12 PM
i get the error again when i do that
Title: Re: Search Code?
Post by: IchBin on March 03, 2010, 06:41:22 PM
Which error? Can you post your code? Kind of hard to help if you don't provide any info.
Title: Re: Search Code?
Post by: SN on March 03, 2010, 06:47:41 PM
The same one as i got before
QuoteNot Found

The requested URL /forums/', $scripturl, ' was not found on this server.

i posted the code i'm using a few posts before. Then you mentioned that i should not have the action link there, so i removed it and done what you suggested. Then when i try to search i get that error again which i posted a few posts before also.

This is only when the global code is in front of the ?>. With the action link it works fine but with out it, i get that error when i try to use the search bar.

By the way every thing is displaying ok, looks just how i want it. Just the search isn't actually working