我有一個從hook_form實現的窗體,名爲simplequiz_form()我想在下面提交之後訪問它的數據是我寫的代碼,但我似乎無法訪問它數據一旦提交。我究竟做錯了什麼 ?如何訪問drupal中的hook_form_validate()中的表單數據7
function simplequiz_form_validate($form, &$form_state) {
// here is where we will validate the data and save it in the db.
$thid = db_insert('simplequiz')
->fields(array(
'questions' => &$form_state['question'],
**I can't seem to access the value of a field questions**
))
->execute();
return $thid;
}
下面是我實現hook_form的()
function simplequiz_form($form, &$form_submit)
{
$form['question'] = array(
'#title' => t('Please input your question'),
'#type' => 'text_format',
'#required' => FALSE,
'#description' => t('Here is where you can enter your questions'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
如果我使用$ form_state [ '值'] [ '問題']
我得到下面的錯誤:
PDOException:SQLSTATE [21S01]:插入值列表與列表列表不匹配:1136列計數不匹配值計數a第1行:INSERT INTO {simplequiz}(questions)VALUES(:db_insert_placeholder_0_value,:db_insert_placeholder_0_format);在simplequiz_form_submit()(/home/vishal/Dropbox/sites/dev/sites/all/modules/simplequiz/simplequiz.module的第245行)中的Array([:db_insert_placeholder_0_value] => [:db_insert_placeholder_0_format] => filtered_html)。
它的工作使用$ form_state [「值」] [「問題」] [「值」]
它的工作我不得不改變一下,雖然$ form_state ['values'] ['question'] ['value'] –
只是一句話:沒有hook_form_validate()。這被稱爲「表單驗證處理程序」。 – pfrenssen