News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How To: Create Drop-Down Search List

Started by BigMike82, September 03, 2008, 09:32:50 AM

Previous topic - Next topic

BigMike82

Hi All,

Been trying to write some small code that would do a search on a predefined drop-down search list. For example, if you click the drop-down menu, it lists a number of pre-set queries.

Example:

Drop-Down List:
1. Apples
2. Oranges
3. Bananas
4. Grapefruit

If the user selects oranges, it would search all topic titles with the word oranges....

Thanks,
Mike

Hoochie Coochie Man

İnadına SMF 1.1.X

BigMike82

Hi, thanks!

This is somewhat on the right track, I read through that one already.

The normal search would be to enter a string of text into the search box and hit the Search button. This other way, which I'm trying to code, is to have a drop-down list of search terms that the user can select and it would search all topics with the word in it.

Does that make any more sense?

[SiNaN]

This would help you:

echo '<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;" name="searchForm" id="searchForm">
<select name="search" onchange="document.forms.searchForm.submit();">
<option value="">Select Fruit:</option>
<option value="">--------------</option>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
<noscript><input type="submit" name="submit" value="', $txt[161], '" /></noscript>
</form>';
Former SMF Core Developer | My Mods | SimplePortal

BigMike82

SiNAN,

This works perfect, thanks!

How can I get this feature into the Search Block on Simple Portal?


Thanks,
Mike

[SiNaN]

Create a PHP block and use this codes as the content:

global $scripturl;

   echo '<div style="text-align: center; width:100%;">
<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;" name="searchForm" id="searchForm">
               <select name="search" onchange="document.forms.searchForm.submit();">
                  <option value="">Select Fruit:</option>
                  <option value="">--------------</option>
                  <option value="apple">Apple</option>
                  <option value="banana">Banana</option>
                  <option value="orange">Orange</option>
               </select>
               <noscript><input type="submit" name="submit" value="', $txt[161], '" /></noscript>
            </form>
          </div>';
Former SMF Core Developer | My Mods | SimplePortal

BigMike82

Most excellent! Thanks as always SiNAN.

You can check out the forum: http://www.fantasyplayerthreads.com

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

Rusconipepparoni

Would it be possible to make a drop down list of where you want to search and then a field behind to put the word you want to search for? So basically a list that I'd choose the board "Donations" from and then write "Guide" in the field behind. That would basically search in the board "Donations" for the word "Guide".

That'd be awesome if possible, maybe someone here knows how to do that?  O:)

unrelenting

Quote from: Rusconipepparoni on October 03, 2008, 07:29:28 PM
Would it be possible to make a drop down list of where you want to search and then a field behind to put the word you want to search for? So basically a list that I'd choose the board "Donations" from and then write "Guide" in the field behind. That would basically search in the board "Donations" for the word "Guide".

That'd be awesome if possible, maybe someone here knows how to do that?  O:)

http://yourwebsite.com/forum/index.php?action=search

;D

Rusconipepparoni

Quote from: unrelenting on October 03, 2008, 07:41:52 PM
Quote from: Rusconipepparoni on October 03, 2008, 07:29:28 PM
Would it be possible to make a drop down list of where you want to search and then a field behind to put the word you want to search for? So basically a list that I'd choose the board "Donations" from and then write "Guide" in the field behind. That would basically search in the board "Donations" for the word "Guide".

That'd be awesome if possible, maybe someone here knows how to do that?  O:)

http://yourwebsite.com/forum/index.php?action=search

;D

There's no such search with the same function as i wanted there

[SiNaN]

Actually, you select the boards from the search area. You want to have that functionality on all pages?
Former SMF Core Developer | My Mods | SimplePortal

unrelenting

Quote from: Rusconipepparoni on October 04, 2008, 09:33:51 AM
Quote from: unrelenting on October 03, 2008, 07:41:52 PM
Quote from: Rusconipepparoni on October 03, 2008, 07:29:28 PM
Would it be possible to make a drop down list of where you want to search and then a field behind to put the word you want to search for? So basically a list that I'd choose the board "Donations" from and then write "Guide" in the field behind. That would basically search in the board "Donations" for the word "Guide".

That'd be awesome if possible, maybe someone here knows how to do that?  O:)

http://yourwebsite.com/forum/index.php?action=search

;D

There's no such search with the same function as i wanted there

That's exactly what the advanced search page does.

Rusconipepparoni

Quote from: [SiNaN] on October 04, 2008, 06:06:38 PM
Actually, you select the boards from the search area. You want to have that functionality on all pages?

It does give an option to select which board to search from. But I want a quick search on the top of my page which includes all boards in a drop down input or whatever it's called.

Like this
<select name="icon" id="icon" onchange="showimage()">
<option value="xx" selected="selected">Standard</option>
<option value="thumbup">Thumb Up</option>
<option value="thumbdown">Thumb Down</option>
<option value="exclamation">Exclamation point</option>
<option value="question">Question mark</option>

<option value="lamp">Lamp</option>
<option value="smiley">Smiley</option>
<option value="angry">Angry</option>
<option value="cheesy">Cheesy</option>
<option value="grin">Grin</option>
<option value="sad">Sad</option>

<option value="wink">Wink</option>
<option value="solved">Solved</option>
</select>


Night09

I made a post regarding hardcoded strings but now saw this which is very similar to my issue.

I re wrote the array similar to how you have shown here but cannot work out how to make the labels be drawn from the modsettings file.

When  I look at my form it shows the tabs but the options they should have are all empty still.Here is a chunk of the code how I have tried to do this.

<td><b>Race:</b></td>
                                <td>
                                    <select name="default_options[',$race_i,']">
                                        <option>&nbsp;</option>
                                        <option value="Blood_Elf">', $txt['Blood_Elf'], '</option>
                                        <option value="Draenei">', $txt['Draenei'], '</option>
                                        <option value="Dwarf">', $txt['Dwarf'], '</option>
                                        <option value="Gnome">', $txt['Gnome'], '</option>
                                        <option value="Human">', $txt['Human'], '</option>
                                        <option value="Night_Elf">', $txt['Night_Elf'], '</option>
                                        <option value="Orc">', $txt['Orc'], '</option>
                                        <option value="Tauren">', $txt['Tauren'], '</option>
                                        <option value="Troll">', $txt['Troll'], '</option>
                    <option value="Undead">', $txt['Undead'], '</option>
                    <option value="-1" selected="selected">', '</option>


                                    </select>
                                </td>


As you see I added $txt but they are showing blank still in the tab.The $txt have been added to modsettings file but im not sure its actually looking there.

I figured this thread is more appropriate than the one I started and will request the admin remove mine if it is.If not I apologise for posting here. :)

jonrs

Hello! I am creating a website and I want to put a multiple drop down search box:

example:

Quick Search
         Propety:  [             ]
         Location: [             ]
         price:       [             ]
               
                           [Searc]

i tried to create the form in flash and dreamweaver but i dont know how to make the php to show the results or to direct to the searchresult..

Can somebody please teach me the codes. Thanks
         

Advertisement: