Monday, October 5, 2009

CCK Automcomplete widgets php code

SystemicPlural - September 8, 2009 - 11:58

I'm trying to create an auto complete username field using the 'Autocomplete Widgets for CCK Text and Number' module.

I've created a new 'Autocomplete for existing field data' field and have added the following code into the defaults > PHP box. (minus the php tags)

$sql = 'SELECT uid,name FROM {users} WHERE name LIKE '%s%%' ORDER BY name ASC';
$result = db_query($sql, arg(2));
$users = db_result($result);
return array(array(
'value' => $users ));
?>

I get the following error.

The default value PHP code returned an incorrect value.
Expected format:

return array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued:
1 => array('value' => value for value),
2 => ...
);

Returned value:

Thanks for any help.
What am I doing wrong?

fixed a bug in php code.

SystemicPlural - September 8, 2009 - 12:56
$sql = "SELECT uid,name FROM {users} WHERE name LIKE '%s%%' ORDER BY name ASC";
$result = db_query($sql, arg(2));
$users = db_result($result);
return array(array(
'value' => $users ));
?>

Still looking for an answer though.

Not even sure I should be putting this code in the php defaults text box.

I'm Simply trying to create an auto complete username textbox.

No comments:

Post a Comment