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?

1 Answer 1


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

//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.
    Commented Oct 11, 2012 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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