I'm creating an initial Webform as a template in my custom_module.install file like this:

  // Create a new Webform node.
  module_load_include('inc', 'node', 'node.pages');

  $form_state = array();
  $form_state['values']['title'] = 'Webform template';
  $form_state['values']['name'] = 'Demo User';
  $form_state['values']['op'] = t('Save');

  $node = array('type' => 'webform');
  drupal_execute('story_node_form', $form_state, (object)$node);

All seems to work, but I get some variation of this error:

Duplicate entry '637-1' for key 1 query: INSERT INTO webform_roles (nid, rid) VALUES (637, 1) in /var/www/sites/all/modules/webform/webform.module on line 496.

Is this anything I should worry about? Is there something more I should include in the form_state values?

Comments

quicksketch’s picture

Generally node_save() works better than drupal_execute() for creating nodes through PHP. I'd suggest doing node_load($nid) on an existing Webform node, look at all the properties and make that a template for creating a new Webform node. Make sure $node->nid is empty, then call node_save($node) on your new node.

quicksketch’s picture

Status: Active » Closed (fixed)