2014-09-04 82 views
2

我試圖在數據庫中保存表單狀態並希望在列表頁面中查看其錯誤驗證。如何顯示/驗證節點列表頁面的錯誤

即,我想從我的數據庫驗證以前保存的表單狀態。

這是一個節點類型表單。

我已經試過node_validate它不工作,因爲我在提交節點之前獲取數據。所以沒有NID併爲它不工作

,並試圖drupal_validate_form卻是露出

[form_token] => The form has become outdated. Copy any unsaved work in the form below and then reload this page 

編輯
任何一個有任何幫助,「如何保存表單輸入中數據庫和數據庫進行形式submision retrive它。

預先感謝您

任何幫助是最值得重視的。

回答

2

如果您在Drupal核心看,你看這includes/form.incdrupal_validate_form功能:

if (isset($form['#token'])) { 
    if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) { 
     $path = current_path(); 
     $query = drupal_get_query_parameters(); 
     $url = url($path, array('query' => $query)); 

     // Setting this error will cause the form to fail validation. 
     form_set_error('form_token', t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url))); 

     // Stop here and don't run any further validation handlers, because they 
     // could invoke non-safe operations which opens the door for CSRF 
     // vulnerabilities. 
     $validated_forms[$form_id] = TRUE; 
     return; 
    } 
    }` 

這說明「的形式已經過時」正在這裏設置郵件。因此,您可以通過取消設置#token來使isset($form[#token'])條件爲false,以防止出現此消息。

您只需加載要驗證的表單狀態,然後在致電drupal_validate_form之前致電 unset($form[#token']);

+0

謝謝你的回覆,但我已經解決了,是的沒有設置#token使它 – Lucifer 2014-09-15 07:28:36

+0

你能告訴我爲什麼drupal_validate_form不執行所需的字段驗證 – Lucifer 2014-09-15 14:55:09