Drupal 7 以编程方式保存内容类型上的数据

Drupal 7 以编程方式保存内容类型上的数据,drupal-7,Drupal 7,我刚刚创建了一个内容类型“Cars”,如何以编程方式从表单保存“Cars”上的数据 function form_tutorial_my_form_submit($form, &$form_state){ $title = $form_state['values']['title']; $body = $form_state['values']['body']; $field_color = $form_state['values']['field_color'];

我刚刚创建了一个内容类型“Cars”,如何以编程方式从表单保存“Cars”上的数据

function form_tutorial_my_form_submit($form, &$form_state){
    $title = $form_state['values']['title'];
    $body = $form_state['values']['body'];
    $field_color = $form_state['values']['field_color'];
    $nid = db_insert('cars')->fields(array(
        'title' => $title,
        'uid' => 1,
        'created' => REQUEST_TIME
    ))->execute();
}

如果要保存新节点,请使用以下命令

function form_tutorial_my_form_submit($form, &$form_state){
    $title = $form_state['values']['title'];
    $body = $form_state['values']['body'];
    $field_color = $form_state['values']['field_color'];
    $nid = db_insert('cars')->fields(array(
           'title' => $title,
           'uid' => 1,
           'created' => REQUEST_TIME
    ))->execute();

    // Save new node 
    $node = new stdClass();
    // Set node title
    $node->title = $title;
    // set node type ex: article etc
    $node->type = "YOUR_NODE_TYPE";
    // set node language
    $node->language = LANGUAGE_NONE;
    //(1 or 0): published or not
    $node->status = 1;
    //(1 or 0): promoted to front page
    $node->promote = 0; 
    $node->body['und'][0]['value'] = $body;
    $node->body['und'][0]['format'] = 'full_html';
    node_object_prepare($node);
    node_save($node);   
}

希望这对您有用。

如果要保存新节点,请使用以下命令

function form_tutorial_my_form_submit($form, &$form_state){
    $title = $form_state['values']['title'];
    $body = $form_state['values']['body'];
    $field_color = $form_state['values']['field_color'];
    $nid = db_insert('cars')->fields(array(
           'title' => $title,
           'uid' => 1,
           'created' => REQUEST_TIME
    ))->execute();

    // Save new node 
    $node = new stdClass();
    // Set node title
    $node->title = $title;
    // set node type ex: article etc
    $node->type = "YOUR_NODE_TYPE";
    // set node language
    $node->language = LANGUAGE_NONE;
    //(1 or 0): published or not
    $node->status = 1;
    //(1 or 0): promoted to front page
    $node->promote = 0; 
    $node->body['und'][0]['value'] = $body;
    $node->body['und'][0]['format'] = 'full_html';
    node_object_prepare($node);
    node_save($node);   
}

希望这对您有用。

如果要保存新节点,请使用以下命令

function form_tutorial_my_form_submit($form, &$form_state){
    $title = $form_state['values']['title'];
    $body = $form_state['values']['body'];
    $field_color = $form_state['values']['field_color'];
    $nid = db_insert('cars')->fields(array(
           'title' => $title,
           'uid' => 1,
           'created' => REQUEST_TIME
    ))->execute();

    // Save new node 
    $node = new stdClass();
    // Set node title
    $node->title = $title;
    // set node type ex: article etc
    $node->type = "YOUR_NODE_TYPE";
    // set node language
    $node->language = LANGUAGE_NONE;
    //(1 or 0): published or not
    $node->status = 1;
    //(1 or 0): promoted to front page
    $node->promote = 0; 
    $node->body['und'][0]['value'] = $body;
    $node->body['und'][0]['format'] = 'full_html';
    node_object_prepare($node);
    node_save($node);   
}

希望这对您有用。

如果要保存新节点,请使用以下命令

function form_tutorial_my_form_submit($form, &$form_state){
    $title = $form_state['values']['title'];
    $body = $form_state['values']['body'];
    $field_color = $form_state['values']['field_color'];
    $nid = db_insert('cars')->fields(array(
           'title' => $title,
           'uid' => 1,
           'created' => REQUEST_TIME
    ))->execute();

    // Save new node 
    $node = new stdClass();
    // Set node title
    $node->title = $title;
    // set node type ex: article etc
    $node->type = "YOUR_NODE_TYPE";
    // set node language
    $node->language = LANGUAGE_NONE;
    //(1 or 0): published or not
    $node->status = 1;
    //(1 or 0): promoted to front page
    $node->promote = 0; 
    $node->body['und'][0]['value'] = $body;
    $node->body['und'][0]['format'] = 'full_html';
    node_object_prepare($node);
    node_save($node);   
}

欢迎ram,如果喜欢ans,请将其标记为正确。欢迎ram,如果喜欢ans,请将其标记为正确。欢迎ram,如果喜欢ans,请将其标记为正确。欢迎ram,如果喜欢ans,请将其标记为正确。欢迎ram,如果喜欢ans,请将其标记为正确。