2013-04-14 26 views
0

我有我的網頁上的數據庫(mytheme_page_preprocess函數中的數據庫的幾個查詢)的一些輸出數據,我想做搜索表單(文本字段和提交按鈕)。那麼,我如何才能在預處理函數中獲取表單提交的值?如何獲取表單中提交的值在page_preprocess函數在drupal 7

類似於在myform_form_submit($ form,$ form_state)中的$form_state['values'],但在預處理函數中。

我簡單的搜索

function reestr_form($form, &$form_state) 
{ 
    $form = array(); 
    $form['q'] = array(
         '#type' => 'textfield', 
         '#size' => 30, 
         '#default_value' => t(''), 
        ); 
    $form['submit'] = array(
          '#type' => 'submit', 
          //'#value' => 'send', 
          '#name' => 'op', 
          '#src' => base_path() . path_to_theme() . '/images/search-button.png', 
          '#submit' => array('reestr_form_submit') 
          ); 
    //$form['#submit'][] = 'reestr_search_submit'; 
    return $form; 
} 

function reestr_form_submit($form, &$form_values) 
{ 
    $message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r($form_values, true) . '</pre>'; 
    var_dump($message); 
} 

回答

0

如果template_process_HOOK是表單的一部分,你應該有訪問您的實體$variables['form']['#entity']

/** 
* Implements template_process_HOOK(). 
*/ 
function mymodule_preprocess_myhook(&$variables) { 
    $entity = $variables['form']['#entity']; 
    $field_name = $variables['form']['#field_name']; 
    $info = field_info_field($field_name); 
    $instance = field_info_instance($entity->entityType(), $field_name, $entity->type); 
} 

替代地使用一些ctools緩存(ctools_object_cache_set()/ctools_object_cache_get())或經由form_get_cache()從高速緩存加載的形式。

-1

因爲它是一個搜索表單,如何使其使用GET,並搶得了$ _GET數組中的預處理功能的價值?無論如何,GET通常都建議用於搜索表單,因此結果可以收藏並共享。

喜歡這個:https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#method

+0

感謝邁克,是的,我認爲它,但如何提交GET乾淨的網址?我的意思是URL像'http://example.com/node/11?search = smth'? – inJakuzi

+0

像這樣:http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#method –

相關問題