Hi, is it possible to create an entire webform with form components, from another module?

I'm writing a module that creates a table based on the information in a form, but to keep the values consistent it would be best if I could create a webform as soon as the module is installed.. Is this possible? I've looked through some documentation and couldn't find it, I would appreciate it if anyone could point me to the appropriate documentation or has a workaround on how to achieve this..

Thank you!!

Comments

jimmykramer’s picture

I'm not sure I really understand your issue. What is the underlying problem that is keeping you from just making the webforms the way it was designed to work?

smgregory’s picture

OK, hopefully this helps clarify why I want to do it this way, and not just create a webform from the drupal frontend..

I'm creating this module on one server, but the module will need to be installed elsewhere. Because of the way webform stores its submissions, and the way my table grabs the values, it's very important that each field comes in a certain order, i.e. field1 first, field2 second...

Because I may not be the person installing this module, I'd rather not have faith that the user will create the forms in the correct order and would like to create the web form when the module is installed. I know to use the .install file and add the function that will create the webform to modulename_install, but I'm not entirely sure how to create a webform with components inside a module.

quicksketch’s picture

Since Webforms are nodes, you can just build up a node object and call node_save() on it. If you want to "export" your Webform, just do a var_dump() on the result of a node_load().

quicksketch’s picture

Speaking of which, you can also just use the http://drupal.org/project/node_export module on a Webform node and paste that code into your install function, followed by node_save().

smgregory’s picture

Thank you quicksketch, this is exactly the kind of thing I was looking for.. But there is one last hitch, in ensuring that the nid used will be free..

smgregory’s picture

Status: Active » Closed (fixed)

Figured out that last hitch, simple db query.. Thanks again for the help, this has always been a very helpful community!