【问题标题】:How to add content (post) of content type using form by user如何使用用户表单添加内容类型的内容(帖子)
【发布时间】:2015-09-16 13:31:44
【问题描述】:

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

【问题讨论】:

    标签: forms drupal drupal-7 content-type


    【解决方案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
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2020-09-21
        • 1970-01-01
        • 2013-05-29
        • 2013-05-13
        • 2023-03-30
        • 1970-01-01
        • 2021-03-01
        • 1970-01-01
        • 2014-03-20
        相关资源
        最近更新 更多