2011-12-15 10 views
7

मेरे पास एक बहु-पृष्ठ फ़ॉर्म है। पृष्ठ 1, पृष्ठ 2 और फिर पृष्ठ पर जाएं 3. पुश रीफ्रेश करें (f5) और फॉर्म पृष्ठ 2 पर वापस चला जाता है।ड्रूपल बहु-फॉर्म पेज रीफ्रेश पर राज्य खो देता है

यह ड्रूपल -6 के साथ है। समस्या इस http://drupal.org/node/1060290 के समान दिखती है।

form_cache डेटाबेस तालिका के माध्यम से समस्या में खोदना। वहां पृष्ठ 1 और 2 डेटा दोनों दिखाई देते हैं। PHP डीबगर में ऐसा लगता है कि एक नया form_id बनाया गया है। अर्थात। storage_form-1add3819cbea88139679819935a69686 डेटाबेस कैश तालिका में कुंजी है और फॉर्म-बीसीएफ 9 556f57f5352a57dfbba4c2120ee7 रीफ्रेश पर '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

आप '# ajax' या' # तत्वों ahah' है? क्योंकि मामले में चीजें थोड़ा अलग हैं। आप यहां एक नज़र रखना चाहेंगे: http://drupal.org/node/650016 – Max

+0

यह एक अच्छा बिंदु है। पिछला पृष्ठ जो विफल रहता है #ahah करता है। ड्रूपल 'नया कैश' करता है और फिर पुराने कैश को हटा देता है। लेकिन जब आप इस मामले में रीफ्रेश करते हैं तो नए कैश में कोई पॉइंटर नहीं होता है। इसे सत्र में रखने के लिए कोई जगह नहीं मिल सकती है। जब तक यह फ़ॉर्म बनाता है तब तक कैश नहीं होता है और फिर आपको जो भी मिलता है वह एक स्ट्रिंग है। अभी भी देख रहा है। – Interlated

+0

मुझे नहीं लगता कि आपको अपना डेटा सहेजने के लिए सत्र का सहारा लेना है। सबसे अच्छी बात यह है कि '# आह' तत्वों के साथ एक बहु-चरण फ़ॉर्म का एक अच्छा कामकाजी उदाहरण ढूंढना और वहां से शुरू करना होगा। दुर्भाग्य से मैं एक के बारे में नहीं सोच सकता लेकिन वहां एक मॉड्यूल होना चाहिए। यहां से एक अच्छा लेख है जो स्पष्ट रूप से उसी चीज से संघर्ष कर रहा था जैसा आप हैं: http://www.designend.net/en/webmaster-blog,drupal-ahah-multistep-ahah-forms-with-proper-ahah- व्यवहार – Max

उत्तर

1

आप $ form_state का उपयोग करते हैं [ 'पुनर्निर्माण'] _submit समारोह में सही = फॉर्म के राज्य सहेजा जाता है और डिफ़ॉल्ट मानों के लिए इस्तेमाल किया जा सकता है।

चेक इस उदाहरण: http://www.ferolen.com/blog/how-to-create-multistep-form-in-drupal-6-tutorial/

संबंधित मुद्दे