Hi there,

I have a website with two custom node types. One of them is an application form (it's my custom node) and the other one is a node with some of the application's form data (it's CCK). I'm writing a module to automatically create a new cck node using the data from selected custom node. I made a new tab for my custom node called 'autopublish'. I want it to redirect to a new node form that will be automatically filled (so a ready $node object with proper field names has to already be there) and ready to submit. So using drupal_execute won't have the proper effect (since it automatically submits a form). How can I automatically pass the node object (I already took care to convert the field names in this node object) to a new cck node form?

Comments

pielgrzym’s picture

All I needed was to simply invoke drupal_get_form('myform_id', $node). The $node is important - this doesn't seem to be documented. It passes a ready to rock node object to a newly created form. Since the form default values are fetched from $node object the form will automatically be populated (providing object's field match form's fields, but this is really easy to be done).

Anyways - invoking drupal_get_form is not quite the API way. What consequences can it have? I already took care to fill all the special fields like 'name' or 'uid' :)

--
Pielgrzym

pielgrzym’s picture

I'm posting this if anyone else has problems with automatic assigning a taxonomy. Since it's an object nested in array you have to do some mambo jumbo:

$node = array(
'taxonomy' => array(
      1 => (object)array('tid' => $your_choosen_term_id, 'vid' => $your_beloved_vocabulary_id),
      )
);

Hope it'll help somebody sometime :)

--
Pielgrzym