Hi,

I have PHP code for the "Allowed values list" that grabs some values from the database. The widget type is set to: Text Field With Autocomplete, but even if I try to submit a value that should be allowed by the code, I get a "Illegal value for [my fieldname]." message.

To test to see what values the PHP code is generating, I changed the widget to "Select list", and it did show the value I entered in the select dropdown box.

Can anyone please help? I'm really stuck.

Comments

tj2653’s picture

If it helps, my PHP code looks something like this (without the PHP tags):

$sql = 'SELECT title FROM .......';
$res = db_query($sql);
while($row = db_fetch_array($res)){
$rows[] = $row['title'];
}
return $rows;

Again, I do get the correct allowed values populated when I use a select list, but it doesn't seem to work when I enter one of the values as a "Text Field With Autocomplete".

Thanks.

webpoga’s picture

This will solve your problem:

$sql = 'SELECT title FROM .......';
$res = db_query($sql);
while($row = db_fetch_array($res)){
   $allwd_value = $row['title'];
   $rows[$allwd_value] = $allwd_value;
}
return $rows;

I tried simulating your problem and it also gives me the same error message. What we miss here is that the array that should be returned must also have keys. It uses the 'key' as some sort of a selector when reading the array. Thinking about what might have caused the error, I also tried entering '0', '1' in the field, and I successfully submitted the form and it displays the correct values.

:) sorry for a late response.

tj2653’s picture

Status: Active » Fixed

Hi webpoga,

Thank you so much!! That seems to work great.

-tj2653

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

rvarkonyi’s picture

Status: Closed (fixed) » Active

Hi!

I'm having a similar problem and hopefully you'll be able to help! I'm using Text field with autocomplete too.

If I get it right, this code concentrates on building the allowed values list based on a different table. What I'd like to achieve is have drupal get the values from the field's own allowed values list. The main target I want to achieve is I don't want the module to check the values ALREADY entered and submitted to a table, I want it to use the field's own allowed values list to generate the autocomplete options. Is that something you could help me with?

Thanks!

Rob

karens’s picture

Status: Active » Closed (won't fix)

Closing old issues. None of us is using the D5 version any more, so hard to provide any support. Sorry.