在 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_Field
和 field_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/