3

How do I add a node from a custom form using ajax? I want it to be submitted in the backend. How will it be if there are custom fields?

4

in drupal you can create node using node_save function as below

$node = new StdClass();//creating a bare node
$node->type = 'answer';//giving it type
$node->status = 1;//give it a published staus
$node->title = "Step up to the FLava";//gives title
$node->body = "Body Body body"; //gives body

node_save($node);
//save it and give it the rest of the attributes`
  • 3
    For custom fields, you just add them in the node before saving it : $node->field_my_custom_field['und'][0]['value'] = 'my value'; – Mika A. Oct 11 '12 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.