Hi Everyone,

In my application I have two content types. When user submits one of the contents, I need to programmatically fill in details for the content of the other type and submit it. For this purpose I think I shoud be using drupal_execute() function.
But where exactly to use this function. I mean is there some function when implemented will get invoked after the submission of a form? I was referring to forms api documentation but with no success. Can someone help me in this regard?

Comments

nedjo’s picture

http://api.drupal.org/api/function/hook_form_alter/

E.g., to add a submit handler to the 'story_node_form' form:


function example_form_story_node_form_alter(&$form, $form_state) {
  $form['#submit'][] = 'example_story_node_form_submit';
}

function example_story_node_form_submit($form, &$form_state) {
  ...
  $node = new StdClass();
  $node->type = 'other_type';
  ...
  node_submit($node);
  // Save a new node of the other type.
  node_save($node);
}

kkinfy’s picture

Hi Thanks a lot, but my problem is bit tricky.

From your example, i can invoke example_story_node_form_submit while submitting example_form_story_node_form. But I also have a requirement to pass on few field values from the invoking form to the invoked form. Please can you tell me ,if this this possible by some means?

nedjo’s picture

The form values submitted are available in the #submit callback in the $form_state['values'] argument.

To see how this works, you can study some of the functions in Drupal core whose names end in _submit.

http://api.drupal.org/api/search/6/_submit

e.g. a simple one: http://api.drupal.org/api/function/example_form_submit/6