JavaScript - CCK Text Fields in the Node Object // Cross-method Insights


// Modules
// // # SERVICES 6.x-2.0 and JSON SERVER 6.x-2.0-alpha1

// + + Data Object


Node.Save (and edit)

http://drupal.org/node/774116

///////// CCK TEXT FIELDS

In the code box below refer to:

cck_field_a = [{ "value": "my cck field a" }];

// Which translates to:

// cck_field_a = [];
// cck_field_a[0] = {};
// cck_field_a[0].value = "my cck field a";

This is how CCK text fields are formatted.


// // CCK

var cck_field_b_string = "my cck field b";

data.node_object.cck_field_a = [{ "value": "my cck field a" }];

data.node_object.cck_field_b = [{ "value": cck_field_b_string }];

// // Title

// // // CCK fields are placed in the node_object, just as the basic 'title' is placed there

data.node_object.title = "New Post. Title: " + cck_field_b_string;

// Etc

Refer back to // // http://drupal.org/node/774116

// #### Reference: Services & JavaScript

JavaScript - Node.Save & Edit // Cross-method Insights
http://drupal.org/node/774116

JavaScript - CCK Fields in the Node Object // Cross-method Insights
http://drupal.org/node/776122

JavaScript - Comment.Save
http://drupal.org/node/788892

JavaScript - JSON Server // Request.JSON (MooTools Example)
http://drupal.org/node/522942

JavaScript - JSON Server // Request.JSONP (MooTools Example)
http://drupal.org/node/791922

Comments

epiphanydigital’s picture

If you're using the JSON_SERVER (maybe not even that) and have some custom CCK fields, you might want to do something like this. It works fine for basic fields... not sure about more complex ones.


    $node = new stdClass();
    $node->type         = $edit[type];
    $node->nid          = $edit[nid];
    $node->title        = $edit[title];
    $node->body         = $edit[body];
    $node->uid          = $edit[uid];
    $node->status       = 1;
    foreach ($edit as $key => $value) {
      if (substr($key, 0, 6) == "field_") {
        $node->{$key}[0]['value'] = $value[0]->value;
      }
    }

    // Setup form_state
    $form_state = array();
    $form_state['values'] = (array)$node;
    $form_state['values']['op'] = t('Save');

    $ret = drupal_execute($node->type .'_node_form', $form_state, $node);