Forums

AutoComplete with a remote database

Austre 29 Nov, 2012
Hi,

I need to implement an Autocomplete field in my CF and i don't know if with Autocomplete Processor and Loader i can do it works.

The data is in a SQL Server and not the same database where Joomla is.

So, first question is: Autocomplete Processor and Loader will help me?

If yes, i'll need some How-To cause i'm in doubt what Events i need to make it work. I have some shortly experience with populate DropDown querying data from remote database by Ajax and PHP events.

If no, should i try http://digitarald.de/project/autocompleter/ looks like GreyHead suggest at this post?
GreyHead 29 Nov, 2012
Hi autre,

Provided that the database is accessible and readable form Joomla! then you should be able to do this. You can access a remote database using a Custom Code action to execute a MySQL query. The Joomla! code for making the connection is in this FAQ

Bob
Austre 29 Nov, 2012
Hi Bob!

Connect to my SQL Server is not the problem. I got it from what i learn in my other posts/reply:
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=87095
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=87412
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=2&t=87063

I create a field named 'sad_fav'
[attachment=2]cf_autocomplete_field.JPG[/attachment]

I put the Autocomplete Loader after show HTML, is that wrong?
[attachment=1]cf_autocomplete_loader.JPG[/attachment]

And finally the AutoComplete Processor inside an Event named changeFavorecido
[attachment=0]cf_autocomplete_processor.JPG[/attachment]

So, i had to use Request.HTML to populate some DropDown at this same form that i want the AutoComplete. For it works i need to make something like what i made for my Dropdowns?

I don't know if that line 1 at Autocomplete Processor is required!?
GreyHead 29 Nov, 2012
Hi austre,

I think that is OK except that I'd probably put the AutoComplete Loader before the Show HTML action but it may make no difference.

I think that if you don't select a table you can ignore the Field Name box.

What is the rest of the code you have in the AutoComplete Processor code box?

Bob
Austre 30 Nov, 2012
Back to work!😀

Bob,

The Autocomplete Processor Code is:

<?php
$search =& JRequest::getString('sad_fav', '', 'post');
$conn = mssql_connect("MyServer", "MyUser", "MyPass");
$bco = mssql_select_db("MyDB", $conn);
$sql  = "exec MySP '%'.$search.'%'";
$result = mssql_query($sql,$conn);
$favorecido = array();

while($row=mssql_fetch_array($result,MSSQL_ASSOC)){
 $favorecido[] = $row['NOME'];
}

$form->data['_PLUGINS_']['autocomplete_processor']['result'] = $favorecido[];
mssql_close($conn);
?>


I was trying with the $form->data['_PLUGINS_']['autocomplete_processor']['result']
GreyHead 30 Nov, 2012
Hi austre,

Please try removing the final [] from:
$form->data['_PLUGINS_']['autocomplete_processor']['result'] = $favorecido;

Bob
Austre 30 Nov, 2012
Great News!

It's working, but the response looks like empty. See tab 'Resposta' (Result), the value is [].

[attachment=2]cf_autocomplete_console01.JPG[/attachment]
[attachment=1]cf_autocomplete_console02.JPG[/attachment]
[attachment=0]cf_autocomplete_console03.JPG[/attachment]
GreyHead 30 Nov, 2012
Hi austre,

Hmmm . . . it looks as though $favorecido is empty. You could try adding this as a debug line and see if it shows up in the Response tab:
echo print_r($favorecido, true);


Bob
Austre 04 Dec, 2012
Hi Bob,

I tried that code, but Respose was the same "[]". I tried too echo some string looks like code below, but Response is the same "[]".

echo 'Hello World!';


Annoying!😲
Austre 05 Dec, 2012
Hi Bob,

I'v been tried those codes below

$favorecido = array("Banana","Maçã","Uva","Maracujá");
$form->data['_PLUGINS_']['autocomplete_processor']['result'] = $favorecido;


$favorecido = array("Banana","Maçã","Uva","Maracujá");
$form->data['_PLUGINS_']['autocomplete_processor']['result'] = $favorecido[];


$form->data['_PLUGINS_']['autocomplete_processor']['result'] = array("Banana","Maçã","Uva","Maracujá");


$form->data['_PLUGINS_']['autocomplete_processor']['result'] = "Banana";


But no one send a Response value.

When i tried use a Joomla table, i realized that the Response works fine (of course) and have a JSON response too.

Could you show me a JSON code that it should work if i put it in my AutoComplete Processor?
Yoshida 04 Feb, 2014
Bob / Austre

Any update on this issue?

I'm stuck in this point, cannot load data into the form, even if its a constant or a predefinied array like the latest post in this thread sent by Austre.

I keep the processor fields Table and Column Name blank. I'm using CF v4, Joomla 2.5, PHP 5.5.6. Could you post an autocomplete processor code example?
This topic is locked and no more replies can be posted.