【发布时间】:2010-12-05 02:01:47
【问题描述】:
这是来自 pro drupal 书籍的示例。
function annotate_admin_settings() {
$options = node_get_types('names');
$form['annotate_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Users may annotate these content types'),
'#options' => $options,
'#default_value' => variable_get('annotate_node_types', array('page')),
'#description' => t('A text field will be available on these content types to
make user-specific notes.'),
);
return system_settings_form($form);
}
但是表单drupal文档,表单样式的builder是这样的。
function mymodule_myform($form_state) {
}
函数中有一个参数($form_state),我什么时候应该使用这个参数。谢谢。
【问题讨论】:
-
我不明白你的意思。这是一个参数,不是吗?如何命名(
$form和$form_state之间的区别)并不重要。 -
Pekka,传递给 system_settings_form() 的 $form 不等同于传递给其他表单构建函数的 $form_state 变量,例如block_add_block_form()。这些变量名称描述了 Drupal 中表单和表单状态之间的实际差异。虽然您是对的,可以使用 2 个变量名来指代同一事物,但这不是这里发生的事情,这也是一种糟糕的编码习惯。
标签: drupal forms drupal-6 drupal-modules