Closed (fixed)
Project:
Webform
Version:
6.x-2.9
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
22 Jul 2010 at 16:45 UTC
Updated:
22 Jul 2010 at 18:09 UTC
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
Comment #1
jimmykramer commentedI'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?
Comment #2
smgregory commentedOK, 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.
Comment #3
quicksketchSince 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().
Comment #4
quicksketchSpeaking 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().
Comment #5
smgregory commentedThank 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..
Comment #6
smgregory commentedFigured out that last hitch, simple db query.. Thanks again for the help, this has always been a very helpful community!