I am working to have #autocomplete_path return a valid entry based on a $node->title from another type node. I have based everything off examples:
http://api.drupal.org/api/function/node_example_form/6
http://api.drupal.org/api/function/user_autocomplete/6

some sections of code..


// section of menu
  $items['art/autocomplete'] = array(
    'title' => 'Autocomplete art',
    'page callback' => 'artist_autocomplete',
    'access arguments' => array('access administration pages'),
    'type' => MENU_CALLBACK);

// section of form
  $form['art_artist'] = array(
  	'#type'=>'textfield',
  	'#title'=>'Artists Name',
  	'#autocomplete_path' => 'art/autocomplete',
        '#reguired' => TRUE,);

// the autoreturn function
function artist_autocomplete($string = '') {
  $matches = array();
  $result = db_query_range("SELECT title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%') AND LOWER(type) = 'artist'", $string, 0, 10);
  while ($artist = db_fetch_object($result)) {
    $matches[$artist->title] = check_plain($artist->title);
  }
  print drupal_json($matches);
}

As I type, the autocomplete works great and I have a complete form when I submit. But, when I preview the form, the textfield is blank. Or, if I elect to save the form, the value is empty. If I call the url, I get { "Value" : "Value" } in the returned page.

I would be grateful for any pointers to help me figure this one out.

Thanks!

Comments

Jamesh’s picture

I discovered #reguired and changed it to #required. But nothing changed. This looks so simple, no idea why the value doesn't make it through the form submit, unless the examples are not complete or are outdated. Still digging.

ranebow’s picture

I found that changing

print drupal_json($matches);
to
drupal_json($matches);

seems to work...