By klaasm on
Hello,
At the moment i'm writing a module for Drupal 6 where I wanted to use the autocomplete function.
I don't know what i'm doing wrong but i always get an error ( "an HTTP error 403 occurred") when I type something in my textfield. (When i use a standard autocomplete path like 'user/autocomplete', there are no problems).
Is there somebody who knows a solution?
The code that i use...
in function test_menu()
$items['test/autocomplete'] = array(
'title' => 'Autocomplete',
'callback' => 'test_autocomplete',
'acces'=> TRUE,
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'test.inc',
);
in form function
$form['plaats'] = array(
'#type' => 'textfield',
'#title' => t('plaats'),
'#size' => 30,
'#autocomplete_path' => 'test/autocomplete',
'#maxlength' => 64,
'#tree' => TRUE,
);
in test.inc
function test_autocomplete($fieldname) {
$matches = array();
$result = db_query_range("SELECT name FROM {plaatsen} WHERE LOWER(name) LIKE LOWER('%%s%%')", $string, 0, 10);
// found wrote into $matches
while ($data = db_fetch_object($result)) {
$matches[$data->name] = check_plain($data->name);
}
// return for JS
drupal_json($matches);
}
Comments
Ok, i found the solution
Ok, i found the solution myself. I had to use "page callback" and "access callback".
This is the corrected code
There was also a little error in test.inc . ( LOWER('%s%%') )
corrected code :
in your test function, how
in your test_menu() function, how do you pass $items in to it?
do you return any values?
Not working here...
I've tried you code and it's not working for me... can you please post a zip of your test module ? I'me currently trying to add autocomplete functionnality to my module but without any success....
Thanks !!
Do you have still problems?
Do you have still problems with it? Normally it should work...
Access Callback saved the day
Your ''access callback' => TRUE,' tip really saved the day for me....thank you!
Though I wonder why is it mandatory?
FYI, I was trying to get the auto-complete feature of the custom profile field (D6) to work.
When I added the access callback all work fine.