function ajax_example_unique_autocomplete

An autocomplete form to look up nodes by title.

An autocomplete form which looks up nodes by title in the node table, but must keep track of the nid, because titles are certainly not guaranteed to be unique.

Parameters

array $form: Form API form.

array $form_state: Form API form state.

  • @return array Form array.
1 string reference to 'ajax_example_unique_autocomplete'
ajax_example_menu in ajax_example/ajax_example.module
Implements hook_menu().

File

ajax_example/ajax_example_autocomplete.inc, line 101

Code

function ajax_example_unique_autocomplete($form, &$form_state) {
    $form['info'] = array(
        '#markup' => '<div>' . t("This example does a node autocomplete by title. The difference between this and a username autocomplete is that the node title may not be unique, so we have to use the nid for uniqueness, placing it in a parseable location in the textfield.") . '</div>',
    );
    $form['node'] = array(
        '#type' => 'textfield',
        '#title' => t('Choose a node by title'),
        // The autocomplete path is provided in hook_menu in ajax_example.module.
'#autocomplete_path' => 'examples/ajax_example/unique_node_autocomplete_callback',
    );
    $form['actions'] = array(
        '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
    );
    return $form;
}