UPD:
Now I have an issue saving the autocomplete form value into DB.
I use my own class extending MoodleQuickForm_autocomplete:
class mod_form_myclass_autocomplete extends MoodleQuickForm_autocomplete {
public function __construct($elementName = null, $elementLabel = null, $options = [], $attributes = []) {
$elementLabel= get_string('blablabla', 'bla'); $lines=file('file.txt',FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES);
foreach ($lines as $line_num=>$line) {
$options[$line_num]=$line;
}
parent::__construct($elementName, $elementLabel, $options);
}
File.txt contains of lines like "Option1", "Option2" etc.
I tried foreach like foreach ($lines as $line_num=>$line) and just like foreach ($lines as $line).
This results in that when filling the form on my site, the autocomplete field shows options as they are in the file.txt: "Option1", "Option2" etc.
But when I submit and save form data to DB, not "Option1", "Option2" values are inserted into table, but their line number in file.txt, like 0,1,2..
How can I fix it? Thanks all!