drupal - 将 CCK 字段添加到 Drupal 7 中的自定义表单

标签 drupal drupal-7 cck

在 Drupal 6 中有一种使用 CCK 的方法可以在我们的自定义表单中附加 CCK 字段,例如:

$field = content_fields('field_name');  // field_name is cck field
(text_field,text_Area,image_field anything.)
$form['#field_info'][$name] = $field;
$form += content_field_form($form, $form_state, $field);

如何在 Drupal 7 中实现相同的功能?我有一个表单,我想使用我为内容类型创建的字段。我浏览了field.module的所有文件但找不到任何东西。里面有_attach_field等功能, field_info_Fieldfield_info_instance ,但它们不能呈现为表单字段。

最佳答案

终于得到了答案。这是做到这一点的技巧。

$node = new stdClass();
$node->type = 'video'; //content type
field_attach_form('node', $node, $form, $form_state);
unset($form['body']); //unset other fields like this.

这将显示使用字段 api 添加的所有自定义字段。所以您需要取消设置您不想在表单中显示的任何额外字段。其余的将像 IT 一样。

关于drupal - 将 CCK 字段添加到 Drupal 7 中的自定义表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854424/

相关文章:

Drupal:自动将新节点添加到节点队列

javascript - 将 Bookmarklet Javascript 添加到 block ?

php - 在 php 代码 drupal 7 中使用 drupal_add_js

php - 如何在 drupal 模块中创建表单?

drupal - Drupal 7 是否有比 Drupal 6 更好的方式来管理开发变更?

image - Drupal - 将灯箱与 View (Rel 属性)一起使用 - 在输出链接中

php - 在模块的安装架构中使用导出的 CCK 内容类型

mysql - 手动修改 CCK 表安全吗?

apache - drupal 未在 default/files/中加载 js/css 文件

Zip 存档支持中显示的 Drupal 运行 update.php 缺失