Jump to content

AJAX autocomplete - only in latin chars


yanipan

Recommended Posts

Hi all,

I've made an auto complete script to complete my usernames when they are typed.

it works great except for only working for latin chars... when I use any utf-8 chars they are dropped and "ignored".

I'm very new, and i'm sure it has somthing to do with the url encoding. i've tried a little debugging, and the chars (both latin and unicode) are passed to the AJAX script no problem. but when they get to the client side script (to query for users with names that containt the string) they appear empty...

I've actually made this script twice - one using simple JS, and once using MOOTOOLS. two times with not a single line of code passed between them... and yet, i've got the same issue on both scripts.

I'm very new to both PHP and JS, and this might be somthing simple that I don't know about, but I really spent lots of time trying many URLencoding  things but for no avail.

I don't even know how to debug it - just that it gets to the AJAX ok, but if I print the var from thephph client side script - its empty (??)...

Thanks

Yanipan.

Link to comment
Share on other sites

if (JRequest::getVar('task')=='listFields') {

  if( $table = JRequest::getVar( 'table', '', 'get', 'cmd' ) ) {

                    $namecard = ( JRequest::getVar('table'));

           

      //      echo $namecard;

                //  $namecard = htmlspecialchars($namecard,'UTF-8');

               

                $namecard = htmlspecialchars_decode($namecard);

            $namecard = htmlspecialchars(stripslashes(trim($namecard)), ENT_QUOTES);

 

             

// Get a database object

$db = JFactory::getDBO();

$query = "SELECT username FROM #__users WHERE username LIKE '".$namecard."%'";

// Executes the current SQL query string.

$db->setQuery($query);

// returns the array of database objects

$list = $db->loadObjectList();

//create the list of titles

echo '<div id="suggestcontainer">';

foreach ($list as $item) {

echo '<div id=singlename>'; 

$item_title = $item->username;

$item_title_highlighted = str_replace($namecard, '<span id="highlighter">'. $namecard .'</span>', $item_title);

echo '<div onclick=entername("'.$item_title.'")';

echo '><div>';

echo $item_title_highlighted.'</div></div></div>';

}

return;

}

return;

}

 

Link to comment
Share on other sites

umm sorry, somthing went wrong when i pasted the code in the previous post, so i'll try again :)

first of all, thanks for the help!

 

the code is:

javascript:

if (JRequest::getVar('task')=='listFields') {
  if( $table = JRequest::getVar( 'table', '', 'get', 'cmd' ) ) {
                     $namecard = ( JRequest::getVar('table'));
             
       //      echo $namecard;
                //  $namecard = htmlspecialchars($namecard,'UTF-8');
                
          //       $namecard = htmlspecialchars_decode($namecard);
          //  $namecard = htmlspecialchars(stripslashes(trim($namecard)), ENT_QUOTES);
          //attempts to fix the input

              
// Get a database object
$db = JFactory::getDBO();
$query = "SELECT username FROM #__users WHERE username LIKE '".$namecard."%'";
// Executes the current SQL query string.
$db->setQuery($query);
// returns the array of database objects
$list = $db->loadObjectList();
//create the list of titles
echo '<div id="suggestcontainer">';
foreach ($list as $item) {
echo '<div id=singlename>';   
$item_title = $item->username;
$item_title_highlighted = str_replace($namecard, '<span id="highlighter">'. $namecard .'</span>', $item_title);
echo '<div onclick=entername("'.$item_title.'")';
echo '><div>';
echo $item_title_highlighted.'</div></div></div>';
}
return;
}
return; 
}

 

client form:

<form action="index.php" name="purpssubmitform">
	<?php echo JText::_('USERTOCHALLENGE');?>
	  <input id="db_tables" type=text name=user>  
	<div id="fields-container">
    </div>
	<input type="submit" name="submit" value="Send Challenge" /></td></tr>
	<tr><td class=sectiontableheader colspan=3> </td></tr>
	<input type="hidden" name="choosepic" value="1" />
	<input type="hidden" name="option" value="com_purps" />
	<input type="hidden" name="act" value="challenge" />
	</form>

 

client JS:

window.addEvent("domready",function(){

$("db_tables").addEvent("keyup",function(){

var url="index.php?option=com_purps&format=raw&task=listFields&table="+this.getValue();
var a=new Ajax(url,{
method:"get",
update:$("fields-container")
}).request();
});
});    

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.