如何使用用户的表单添加内容类型的内容(帖子)

问题描述 投票:0回答:2

我想制作一个允许用户为我的内容类型添加帖子的表单。表单将包含我在内容类型中创建的所有字段。一旦用户提交了from,那么条目将自动添加内容类型。

forms drupal drupal-7 content-type
2个回答
1
投票

您可以在表单提交功能中添加创建新节点

function custom_page_submit($form, &$form_state) {
  global $user;

  //Create new object and fill the fields;
  $node = new stdClass();
  $node->title = "SOME TITLE";
  $node->type = "YOUR_NODE_TYPE";
  node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  $node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
  $node->uid = $user->uid; 
  $node->status = 1; //(1 or 0): published or not
  $node->promote = 0; //(1 or 0): promoted to front page
  $node->comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write

  $node = node_submit($node); // Prepare node for saving
  node_save($node);
  // Display success message
  drupal_set_message("Node was saved!");
  // And you can specify where user shoul be redirected
  $form_state['redirect']  = 'SOME WHERE'; // 'front' - if redirect to front page
}

0
投票

使用通用节点创建系统,并强制它使用前端主题。

© www.soinside.com 2019 - 2024. All rights reserved.