我为俱乐部写了一个模块。我现在拥有的是一个页面,显示一个html表格,显示俱乐部会议室的可用性
我添加了一个指向该表[参考代码示例]最后一列的链接,单击该链接后,用户可以将值从yes更改为no。令人震惊我查询的更新工作,传递参数,但现在我被困在流程上。
现在的工作方式是:
我想要的是:
列出项目
$items['/change_availability/%'] = array(
'title' => 'Change Availability',
'page callback' => 'change_availability_test',
'access arguments' => array('user_access'),
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Change space availability status.
*/
function change_availability_test($rid = NULL, ) {
//This function runs the db update query.
}
if ($form['rid']) {
foreach (element_children($form['rid']) as $key) {
$rows[] = array(
'data' => array(
drupal_render($form['rid'][$key]),
drupal_render($form['squad_name'][$key]),
drupal_render($form['task_id'][$key]),
drupal_render($form['email'][$key]),
drupal_render($form['club_location'][$key]),
drupal_render($form['rating'][$key]['grade']),
l(t('click'), "change_availability/".$key),
),
'class' => $form['status'][$key]['#value'],
);
}
$headers = array(
array('data' => t('id')),
array('data' => t('squad_name')),
array('data' => t('task_id')),
array('data' => t('email')),
array('data' => t('Club Location')),
array('data' => t('Rating')),
array('data' => t('Available?')),
);
$output = theme('table', $header, $rows, array('id' => 'room-listing'));
$output .= drupal_render($form);
}
return $output;
}
答案 0 :(得分:1)
您可以在页面中添加确认表单。有一个Drupal API函数 - confirm_form(),可以帮助您创建这样的表单。
将您的代码更改为:
// In your hook_menu().
$items['change_availability/%'] = array(
'title' => t('Change Availability'),
'page callback' => 'drupal_get_form',
'page arguments' => array('change_availability_test_form', 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
/**
* Form callback for 'change_availability/%' path.
*/
function change_availability_test_form($form, $form_state, $account) {
$form['account'] = array(
'#type' => 'value',
'#value' => $account,
);
return confirm_form($form, t('Are you sure you want to change the availability?'), 'here_goes_your_backurl_for_cancel_link');
}
/**
* Submit callback for 'change_availability_test_form' form.
*/
function change_availability_test_form_submit($form, &$form_state) {
$account = $form_state['values']['account'];
// Call your function
change_availability_test($account);
// Redirect back to te table.
$form_state['redirect'] = 'your_backurl';
}