2

Question: How can I import a Webform via the https://drupal.org/project/webform_share API?

What do I know/current state: The API shows a graphical UI to do it, but I'd need a way to do it via an exported function, if any (e.g. a function call like webform_share_import($formspec)).

Reason/scenario: Because I want to install some forms in the .install of a module.

3 Answers 3

1

Found: there's not an exported API, but an implementation of a regular form hook for the UI, which does all the magic (webform_share.module:123).

1
  • It is disappointing to answer my own questions and find a negative one :(. Mar 10, 2014 at 22:50
0

See this issue.

In the comments, it shows that there is a function called _webform_share_eval() in the webform_share.module file.

function _webform_share_eval($str) {
  eval($str);
  return empty($webform) ? FALSE : $webform;
}

It's very simple to use this to import a webform and save a node.

// Create the node
$node = new stdClass();
$node->type = 'webform';
$node->title = 'Contact Us';
$node->status = 1;
node_object_prepare($node);

// Import the webform
$node->language = 'und';
$node->webform = _webform_share_eval(file_get_contents(drupal_get_path('module', 'mymodule') . '/webform.txt'));
node_save($node);
0

For Drupal 8/9 and Webform 6, there is now a Webform Share submodule in Webform itself.

This can be used to use webforms in decoupled situations.

There is a video tutorial here.

Basic config info for global sharing of webforms:

First, go to /admin/structure/webform/config and Enable form sharing under Form share settings.

Then go to /admin/structure/webform, click the more info triangle, select Share, and then choose from among the three options to embed your webform.

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.