私は複数ページのフォームを持っています。 1ページ目、2ページ目、3ページ目を表示してください。リフレッシュ(f5)を押すと2ページ目に戻ります。Drupalマルチフォームがページリフレッシュ時に状態を失う
これは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';
}
}
は、あなたが '#のajax'または'#のahah'要素を持っていますか?その場合は事が少し違うからです。あなたはここで見てみたいかもしれません:http://drupal.org/node/650016 – Max
それは良い点です。失敗したページの前のページは#ahahです。 Drupalは '新しいキャッシュ'を実行して古いキャッシュを削除します。しかし、この場合に更新すると、新しいキャッシュへのポインタはありません。また、それをセッションに入れる場所を見つけることができません。フォームをビルドしてから文字列を取得するまでキャッシュしません。まだ見ている。 – Interlated
データを保存するためにセッションに頼る必要はないと思います。最善のことは、 '#ahah'要素を持つ多段階フォームの良い実例を見つけてそこから始めることです。残念ながら私は1つ考えることはできませんが、そこにモジュールがなければなりません。ここからあなたからの素晴らしい記事は、あなたと同じことをしているように見えていたようです:http://www.designend.net/en/webmaster-blog,drupal-ahah-multistep-ahah-forms-with-proper-ahah- – Max