gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:15:45 27 4
gpt4 key购买 nike

在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com