MyBB Community Forums

Full Version: Autocomplete Textbox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I am working with a Tag system. When User Wants to post a thread, He is asked to enter some tags. I want the Tag Text box to be autocomplete.

Firstly here is the code that I have put inside new thread template


<input type="text" class="textbox" name="tags" id="tags" value="" autocomplete="on"/>
<script type="text/javascript" src="{$settings['bburl']}/jscripts/autocomplete.js?ver=1600"></script>
<script type="text/javascript">
<!--
if(use_xmlhttprequest == "1")
{
new autoComplete("tags", "{$settings['bburl']}/xmlhttp.php?action=get_tags", {valueSpan: "tags"});
}
// -->
</script>



Now I updated xmlhtp and added one else if section to handle get_tags

else if($mybb->input['action'] == "get_tags")
{
	// If the string is less than 3 characters, quit.
	if(my_strlen($mybb->input['query']) < 3)
	{
		exit;
	}
	
	// Send our headers.
	header("Content-type: text/plain; charset={$charset}");

	// Sanitize the input.
	$mybb->input['query'] = str_replace(array("%", "_"), array("\\%", "\\_"), $mybb->input['query']);
	
	// Query for any matching usergroups.
	$query_options = array(
		"order_by" => "tags",
		"order_dir" => "asc",
		"limit_start" => 0,
		"limit" => 15
	);
	
	$query = $db->simple_select("tags", "aid", "tags LIKE %'".$db->escape_string($mybb->input['query'])."%'", $query_options);
	while($group = $db->fetch_array($query))
	{
		$group['tags'] = htmlspecialchars_uni($group['tags']);
		// Send the result to the browser for this usergroup.
		echo "<div>\n";
		echo "<span class=\"tags\">{$group['tags']} (Tags {$group['tags']})</span>\n";
		echo "</div>\n";
	}
}




But autocomplete is not performed. Can you please suggest where I am doing wrong?

My site:http://grasshoppernetwork.com
Can you provide a test account? Thanks Smile
(2012-09-25, 03:53 AM)Paul H. Wrote: [ -> ]Can you provide a test account? Thanks Smile


Already Sent to you through PM for site grasshoppernetwork.com

I have got it to work. There was a query problem in xmlhttp.

But as tags table stores tags in , separated single string

If I type say 'Image'

Than it pops up


Image Processing, Detection
Pattern Recognition,Image Processing, Mammogram
Image Segmentation, Matlab


As these strings are stored as single string in tags column

But I need to strip the other strings and Pass only those strings that has Image in it

So I am expecting a result

Image Processing
Image Segmentation


Thats it.

So there are two parts, select a substring containing only the query and remove the duplicate ones.

Anybody Please?

UPDATE

Using Substring I have Solved the above problem and now autocomplte is more or less working ok. But when I click on the scroll of autocomplete pop up table, it is selecting the value rather than popping.


2. How to retain the value in textbox

say when I type Ima

it pops up

Image Processing

I select that, put a comma

Again I type Mat . so now value in my text box is

Image Processing, Mat

and popup box shows matlab

Soon I select Matlab, the text changes to Matlab overriding previous value.

But it should have been

Image Processing, Matlab

I am working on each problem, but my limited php/mysql and css knowledge is not helping me to get it right. Please help.

1) First Install Systema Tags Plugin. It does not support UTF. so you need to workaround for UTF. It does not work in MySql Strict mode, so tweak plugin activate and deactivate sections . Remove entries with NULL and isdefault to '0'

2) Configure the settings and get it in index page. If you are lucky and are using default template, it will work the way it should. If you ever have edited your templates then it will not work for thread display and new threads. You need to search the appropriate template in tags.php and place it manually in your template.

3) Once you use it, it will not permit you to post any threads with less than 5 tags and any tag bellow 5 characters which will drive your poster away from your forum forever. So now goto /inc/plugin and edit systematags.php
you need to find the code that validates this and alter validation and reupload the same.

4) Your thread posting text box will not have any auto complete facility. So you need to add extra function say get_my_tags in xmlhttp.php. Here you need to add an extra else if to handle mybb->input[
get_my_tags']. You need to select tags from tags table and return html table containing one tag in each row.

5) MyBB has a slight error ( I do not know may be my browser) in autocomplete.js in /javascript folder. if you have many options and when you click on the scrollbar, it just selects the last value rather than scrolling. As you might have many tags, you need the table to be of more height. find and change maxHeight parameter in the javascript

6) comeback to your new thread template from ACP and use delimeter ',' option with autocomplete. and remember to pass get_my_tags in autocomplete.

7) If you want to generate RSS of your tag: You need to update Syndicate.php and add an extra section to handle id=tag like it handles id=fid

8) create a RSS URL dynamically in tag.php in listthread section to accomodate this syndicate.

Now your tag system is ready. My MyBB knowledge is poor and php and mysql is not good either. so I am not posting any code. However more experienced coders here can guide you based on this logic if any of you happen to come over here looking for tags in MyBB.

=========================================
End Note: Is it really the worth of time? Probably only 1 in 1000 visitors in your site will ever use a Tag, but you know what, if you really have diverge data, you will understand the difference. When you write Mobile in tag box, it will also suggest Android and J2Me. Its power of data and datamining. If you dont use a tag system, you will probably regret sooner than later IMO. Good Luck.

http://grasshoppernetwork.com