yanipan Posted January 23, 2010 Share Posted January 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
iScript Posted January 25, 2010 Share Posted January 25, 2010 Can you put here the code? I'll try to fix it for ya. Quote Link to comment Share on other sites More sharing options...
yanipan Posted January 25, 2010 Author Share Posted January 25, 2010 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; } Quote Link to comment Share on other sites More sharing options...
yanipan Posted January 25, 2010 Author Share Posted January 25, 2010 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(); }); }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.