我在Drupal 7上为mu网站制作了一个自定义模块。页面上应该有几个组合框,所以我创建了一个包含多个选择的表单。选择的选项取自数据库。
现在有三个方框:' speaker',' year',' booknumber'。 '扬声器'和' booknumber'工作完美,但' year'弄错了。有数百个选项不应该,以及从我的数据库中获得的6个元素。据我所知,错误的元素出现在" options_years'数组,因为' query_year'仅包含这6个元素。
我试图做的事情:
拜托,你能给我一些建议或指示吗?我只是不知道在哪里挖掘:(
这是我的代码:
function corpus_retrieve_speaker() {
$query_speaker = db_select('corpus_text', 'n')
->fields('n', array('speaker'))
->distinct()
->orderBy('speaker', 'ASC') //Most recent first.
->execute();
return $query_speaker;
}
function corpus_retrieve_year() {
$query_year = db_select('corpus_text', 'n')
->fields('n', array('year'))
->distinct()
->orderBy('year', 'ASC') //Most recent first.
->execute();
return $query_year;
}
function corpus_retrieve_booknumber() {
$query_booknumber = db_select('corpus_text', 'n')
->fields('n', array('booknumber'))
->distinct()
->orderBy('booknumber', 'ASC') //Most recent first.
->execute();
return $query_booknumber;
}
function corpus_form($form, &$form_state) {
//form speaker combo
$speakers = corpus_retrieve_speaker();
$options_speaker = array();
$i_s = 0;
foreach ($speakers as $unit1) {
$options_speaker[$i_s] = t($unit1->speaker);
$i_s = $i_s + 1;
}
$form['corpus_search_speaker'] = array(
'#type' => 'select',
'#title' => t('Speaker'),
'#empty_option' => t('Choose a speaker'),
'#options' => $options_speaker,
);
//form year combo
$years = corpus_retrieve_year();
$options_years = array();
$i_y = 0;
foreach ($years as $unit2) {
$options_years[$i_y] = t($unit2->year);
$i_y = $i_y + 1;
}
$form['corpus_search_year'] = array(
'#type' => 'select',
'#title' => t('Year'),
'#empty_option' => t('Choose a year'),
'#options' => $options_years,
);
//form booknumber combo
$booknumbers = corpus_retrieve_booknumber();
$options_booknumber = array();
$i_b = 0;
foreach ($booknumbers as $unit3) {
$options_booknumbers[$i_b] = t($unit3->booknumber);
$i_b = $i_b + 1;
}
$form['corpus_search_booknumber'] = array(
'#type' => 'select',
'#title' => t("Book number"),
'#empty_option' => t('Choose a book number'),
'#options' => $options_booknumbers,
);
$form['submit_params'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
return $form;
}
这是选择的HTML,效果很好:
<div class="form-item form-type-select form-item-corpus-search-booknumber">
<label for="edit-corpus-search-booknumber">Book number </label>
<select id="edit-corpus-search-booknumber" name="corpus_search_booknumber" class="form-select">
<option value="" selected="selected">Choose a book number</option>
<option value="0">350</option>
<option value="1">350 (1185)</option>
<option value="2">643</option>
<option value="3">660</option>
<option value="4">732</option>
<option value="5">732 (398)</option>
<option value="6">741</option>
<option value="7">808</option></select>
</div>
这是一段选择的HTML,它不起作用
<div class="form-item form-type-select form-item-corpus-search-year">
<label for="edit-corpus-search-year">Год </label>
<select id="edit-corpus-search-year" name="corpus_search_year" class="form-select">
<option value="" selected="selected">Choose a year</option>
<optgroup label="0"><optgroup label="ru"><optgroup label="">
<option value="Public files">Общие файлы</option>
<option value="Public local files served by the webserver.">Открытый — передачей файлов управляет веб-сервер</option>
<option value="Temporary files">Временные файлы</option>
<option value="Temporary local files for upload and previews.">Временные локальные файлы для загрузки и просмотра.</option>
<option value="Long">Полностью</option>
<option value="Medium">Средн.</option>
<option value="Short">Кратко</option>
<option value="done">выполнено</option>
<!-->Cut a lot of other wrong options<-->
<optgroup label="Long month name"><option value="January">января</option>
<option value="November">ноября</option>
<option value="December">декабря</option></optgroup>
<optgroup label="Font weight"><option value="Strong">Жирный</option></optgroup></optgroup></optgroup>
<!-->these are right options<-->
<option value="1">1958</option>
<option value="2">1962</option><option value="3">1967</option>
<option value="4">1972</option><option value="5">1983</option>
<option value="6">1985</option></select>
据我所知,Drupal语言文件(俄语翻译)中有很多错误选项。