我在Drupal中使用time_tracker_simple模块。当有人从下拉列表中选择并点击提交时,它会停留在同一页面上,但该值不会保留。如何在选中时保留下拉列表的值。
以下是模块中使用的代码。
function time_tracker_simple_timer_form($form_state) {
global $user;
$active_timer = _time_tracker_simple_get_timer();
//*** Both start and start buttons must actually be on the form for #submit to work correctly
$form['stop'] = array(
'#value' => t('Stop'),
'#type' => 'submit',
'#weight' => 20,
'#access' => FALSE,
'#button_type' => 'timer_control_stop',
'#submit' => array('time_tracker_simple_timer_stop'),
);
$form['start'] = array(
'#value' => t('Start'),
'#type' => 'submit',
'#access' => FALSE,
'#weight' => 20,
'#submit' => array('time_tracker_simple_timer_start'),
'#button_type' => 'timer_control_start',
);-----This part is the drop down list------
$activities = array();
$activities[] = '(none)';
$results = db_query("SELECT * FROM {time_tracker_activity} ORDER BY weight ASC");
while ($result = db_fetch_object($results)) {
$activities[$result->taid] = $result->name;
}
if (count($activities) > 1) {
// The activity choser
$form['activity'] = array(
'#title' => t('Activity'),
'#type' => 'select',
'#weight' => 5,
'#options' => $activities,
);
}
答案 0 :(得分:0)
drupal form api允许您将默认值传递给表单项,如下所示:
$form['activity'] = array(
'#title' => t('Activity'),
'#type' => 'select',
'#weight' => 5,
'#options' => $activities,
'#default_value' => $form_state['post']['activity']
);