Drupal autocomplete form, multiple values I have created custom module to add user awards. This award = some text(like Php developer of the month) and image, and i need to implement feature, which can add this award to multiple users in this form
This is my form:

function user_awards_admin_settings() {
    $form = array();
    $form['award_description'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; 'award description',
    );

    $form['name'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('Assign to'),
        '#autocomplete_path' =&gt; 'user_awards/autocomplete',
    );
    $form['user_awards_block_image'] = array(
        '#type' =&gt; 'managed_file',
        '#name' =&gt; 'user_awards_block_image',
        '#title' =&gt; t('Block image'),
        '#size' =&gt; 40,
        '#description' =&gt; t("Image should be less than 400 pixels wide"),
        '#upload_location' =&gt; 'public://'
    );

    $form['#submit'][] = 'user_awards_settings_submit';
    return system_settings_form($form);
}


And this is my autocomplete function:

function user_awards_autocomplete($string) {
    $matches = array();
    $return = db_query("SELECT name FROM users where lower(name) like '" . $string . "%' LIMIT 10");
    // add matches to $matches
    foreach ($return as $row) {
        $matches[$row-&gt;name] = check_plain($row-&gt;name);
    }
    // return for JS
    drupal_json_output($matches);
}


And submit one:

function user_awards_settings_submit($form, $form_state) {
    $file = '';
    if (isset($form_state['values']['user_awards_block_image'])) {
        $file = file_load($form_state['values']['user_awards_block_image']);

        $file-&gt;status = FILE_STATUS_PERMANENT;

        file_save($file);
    }
    $description = $form_state['input']['award_description'];
    $name = $form_state['input']['name'];
    db_query('INSERT INTO {user_awards} (name, award_description, fid) VALUES (:name, :award_description, :fid)', array(
        ':name' =&gt; $name,
        ':award_description' =&gt; $description,
        ':fid' =&gt; $file-&gt;fid,
    ));
    drupal_set_message('form has been submitted');

}


I need somehow to make $form['name'] to be multiple(autocomplete) textfield, comma separated or so, how can i do it?
At this moment its only autocomplete first value of NAME field
Add a select list to your form. Add some #ajax to your textfield. Every time the textfield changes content, add the value (via #ajax) to your select list. Use the values of your select list in the submit callback.

OR

You could to it by attaching a custom JavaScript file using $form['#attached']['js'] with some good old JavaScript to fetch the users and add them to the csv textfield (autocomplete). Then split the values in the submit and add them to the database.

OR

Just use a select if that's OK with you.