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' => 'textfield',
'#title' => 'award description',
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Assign to'),
'#autocomplete_path' => 'user_awards/autocomplete',
);
$form['user_awards_block_image'] = array(
'#type' => 'managed_file',
'#name' => 'user_awards_block_image',
'#title' => t('Block image'),
'#size' => 40,
'#description' => t("Image should be less than 400 pixels wide"),
'#upload_location' => '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->name] = check_plain($row->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->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' => $name,
':award_description' => $description,
':fid' => $file->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