我的页面上有数据库的一些输出数据(在mytheme_page_preprocess函数中对db的查询很少),我想做搜索表单(文本字段和提交按钮)。那么,我怎样才能在预处理函数中获得表单提交的值?
像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 :(得分: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 :(得分:-1)
由于它是一个搜索表单,如何让它使用GET并从预处理函数中获取$ _GET数组中的值? GET通常建议用于搜索表单,因此结果是可收藏和可共享的。
像这样:https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#method