我有一个多页表格。访问第1页,第2页,然后访问第3页。按下刷新(f5),表单返回第2页。
这是drupal-6。该问题与此http://drupal.org/node/1060290类似。
通过form_cache数据库表深入研究问题。第1页和第2页都出现在那里。在php调试器中,它看起来好像已经创建了一个新的form_id。即。 storage_form-1add3819cbea88139679819935a69686是数据库缓存表中的键,form-bcf9556f57f5352a57dfbba4c2120ee7是刷新时的'form_id'。
我的表单代码是什么样的?
主要表格功能:
function myform_online(&$form_state) {
// $form_state['storage']['step'] keeps track of what page we're on.
// start at step 1 if no storage has been set
if (!isset($form_state['storage']['step'])) {
$form_state['storage']['step'] = 1;
}
// If we are saving the form data we should submit rather than display the details.
// At least look at saving the step.
// Don't lose our old data when returning to a page with data already typed in.
$default_values = array();
if (isset($form_state['storage']['values'][$form_state['storage']['step']])) {
$default_values = $form_state['storage']['values'][$form_state['storage']['step']];
}
switch ($form_state['storage']['step']) {
case 1:
// Your Details
module_load_include('inc', 'join_online', 'includes/step1');
我们处理提交:
function join_online_submit($form, &$form_state) {
//Save the values for the current step into the storage array.
//dsm($form_state);
$form_state['storage']['values'][$form_state['storage']['step']] = $form_state['values'];
# ahah - bail.
if ($form_state['ahah_submission']) {
return;
}
// How do we work out if this was a refresh? It currently does start with 1 and think that the step is #2.
//Check the button that was clicked and change the step.
if ($form_state['clicked_button']['#id'] == 'edit-previous') {
$form_state['storage']['step']--;
} elseif ($form_state['clicked_button']['#id'] == 'edit-next') {
$form_state['storage']['step']++;
} elseif ($form_state['clicked_button']['#id'] == 'edit-finish') {
//You should store the values from the form in the database here.
//We must do this or the form will rebuild instead of refreshing.
unset($form_state['storage']);
//Go to this page after completing the form.
$form_state['redirect'] = 'join_online/form/thank-you';
}
}
答案 0 :(得分:1)
如果在_submit函数中使用$ form_state ['rebuild'] = TRUE,表单的状态将被保存并可用作默认值。
检查此示例: http://www.ferolen.com/blog/how-to-create-multistep-form-in-drupal-6-tutorial/