I have attached a patch that will allow you to clone components across forms. For example, Form A has a fieldset called address that you need on form B. Click clone on Form A and the edit form now includes a select box that allows you to choose to clone the address components over to any other forms you have access to. Diffed against 5.x-2.1.3.

Comments

jscheel’s picture

Hrm, just thought of a potential problem. Under advanced settings, the parent select list pulls from the current form, not the destination form. I'm thinking an additional button will be needed, next to the parent field, that allows you to refresh the clone using the selected destination form. Or cloning becomes a two-step process: step 1 - choose destination form, step 2 - edit component settings and save.

izkreny’s picture

This is indeed really cool and needed feature!

Although, it would be nice to port it to 6.x version...

zserno’s picture

StatusFileSize
new3.17 KB

This patch was really helpful for me, thank you.
However it doesn't work for fieldsets with more than 1 level.
I attached a new version that handles this bug.
Explanation in nutshell:
In function webform_component_clone() there is a if statement that is only true in the first iteration of foreach.

  if ($component['clone']) {
    $child_component['nid'] = $component['nid'];
  }

So I simply removed this if statement, since webform_component_clone() is called only by webform_component_edit_form_submit().

zserno’s picture

StatusFileSize
new3.25 KB

Attached the D6 version of patch. Diffed against 6.x-2.1.3

izkreny’s picture

UPDATE: please ignore this post, I found where it is. :)
(although it would be delicious to have option to clone all Form components at once, or to clone whole webform with one click...)

Hi!

I applied across_forms_v2_d6.patch patch against my D6 web site with installed webform version 2.1.3, and I can't find clone option.

Can you please instruct where it should be? Maybe here: /admin/content/webform? Only operations that I can find there are Clear and Edit. :(

Tnx in advance for help, and BIG tnx to zsermo for porting this patch for D6. :)

quicksketch’s picture

I don't know about adding this functionality. How much work is it really to setup a component? In response to mariomaric, you can already clone entire Webforms by using the Node Clone module. Since Webforms are nodes, they work just fine together.

izkreny’s picture

Hello again!

I have some feedback on cloning webform (components across webforms) issue:

1) Cloning Form Components across webforms
If you want to clone all components from one webform to another (already existing!) webform at once, you need to group all components into one fieldset (component). Then when you clone that particular fieldset component, all components beneath are cloned as well. Fieldset magic, it is! ;)
I tested cloning with attached across_forms_v2_d6.patch patch on fieldset, textarea, textfield, hidden and select type of components, and everything worked just fine.

2) Cloning whole webform
I must admit that this is more attractive and faster method! Thank you very much quicksketch for pointing out Node Clone module.
I copied webform node (with fieldset, textarea, textfield, hidden and select type of components) without any problem (using Webform 6.x-2.1.3 and Node clone 6.x-1.0-beta2). And it is really great because you are cloning whole webform with option to have pre-populated all node form fields.

Conclusion: If your web site require even more than one identical webform (with difference in just E-mail to address, for example), then I strongly suggest using Node clone module. In other cloning scenarios using across_forms_v2 patch will save your time as well, and I can't see any harm of implementing it into Webform module (because creating identical form components in other module is really time consuming).

Cheers.

quicksketch’s picture

This patch is well written and adds reasonable functionality, but I'm against it because I wouldn't find it useful, and there's already an existing solution that performs 90% of the use-case for this functionality. The more code that exists in Webform, the more things there are to test (and to break) when maintaining. So my argument against this is there's already a (what I consider) a better solution out there, and it's provided by another module and only to those that need the functionality (therefor installing the module).

daniorama’s picture

Title: Clone across forms » Clone across forms (D5&D6)

I must say this feature is really good, please Quicksketch reconsider adding it. Think about this, there are many Forms that use a lot the same fields. Sometimes we improve or change one of these fields, editing all the copies could be really slow and cloning the module is not an option. (For example, many webforms ask for personal information, that could be 5-7 fields, if later we find that we need another field in the fieldset or we create a validation code for telephone numbers or something like that, it would wonderful to have a way of copying it easily)

Cloning Forms is ok when the forms are nearly the same, cloning fields is good when the forms just have similar things. Thanks

PS: is this working with the last D6 dev version? Does it allow to clone to many forms or just one? If not it would be a really good addition to the patch.

daniorama’s picture

Status: Needs review » Reviewed & tested by the community

It works wonderful with the last dev from D6! Thanks! The only thing that would make it definitive would be an option to clone the field to many forms. I don't know it that would be too difficult but it will make even faster upgrading and developing forms. My website will have 20-25 Forms renovating each month, I really needed this patch and I hope the multiple forms feature will be included. Thanks again!

PS: I change it to reviewed because it seems working to everybody.

mandclu’s picture

I really like this idea. One other possible approach for a solution to clone to one or more webforms would be to have an import/export feature. Imagine, for example, that there was a submodule that created an export tab on your webform. When you go there, you can select which component you want to export, and the filename you want to save to. Then when you're creating a new webform, you can choose to import that list of fields.

There's another module called Multiforms that has a "snippets" feature very similar to this.

jscheel’s picture

Been out of the loop for a while. The big benefit here is for re-usable components. The reason I wrote the initial patch was for a project that involved load application forms. There were several common components in the different forms (e.g. address, company info, etc) that I could clone to the forms where they were needed. Node clone will clone the entire webform, which is fine if you don't need a more a-la-cart approach. For my particular project, node clone was wasting time for me, instead of saving it.

mrfelton’s picture

I think this is a really good patch and would love to see it incorporated into webform officially (subscribing).

rmiddle’s picture

quicksketch,

I had to create a bunch of forms were a section was the same but another section was diff on each form. Granted once #254728: Conditional fields is finished It would have been Turned into 1 form with many branches but that is a moot point right now. I could see this as being useful but as someone who also maintains modules I understand your desire to keep the module clean what about breaking this code into a submodule that the 10% who want this feature can turn on and the other 90% leave turned off? Is that a possible solution?

Thanks
Robert

quicksketch’s picture

Version: 5.x-2.1.3 »
Status: Reviewed & tested by the community » Needs work

I'm extremely unlikely to add this functionality. I'm open to any API changes that would make such functionality possible to include in an add-on module. The 2.x version is feature-frozen regardless, so such a patch will need to be rolled against the 3.x (HEAD) branch.

quicksketch’s picture

Status: Needs work » Closed (won't fix)

Moving to won't fix. As noted above, I'm open to reviewing patches that would enable this functionality through an add-on module.

brenes’s picture

Version: » 7.x-3.15
Status: Closed (won't fix) » Active

Hmm reopening the issue... still think this would be a great enhancement for the webform module or a useful seperate module. I am working with the webform module on drupal 7 and I've got a bunch of nodes for which I want to make some additions to the email form, so that a user is able to select between two different mailing options ("call for offer" and "direct order"). As this part is the same throughout all the nodes of this type it would save me a lot of time to only copy the concerned fields. Any plans to port this patch to drupal 7?
Best Regards

quicksketch’s picture

There aren't any plans to include this feature in the Webform module at all, so porting the patch would be a wasted effort if the goal was to patch the module for inclusion in the project. You'd be better off implementing this as an add-on module.

quicksketch’s picture

Status: Active » Closed (won't fix)
hipfox’s picture

Version: 7.x-3.15 » 6.x-3.x-dev

I have completed this feature, although it is very unpopular, but sometimes useful.

The add-on WFCC module (Webform component clone) that was pushed to my sandbox (http://drupal.org/sandbox/Hipfox/1562236)

It is my first commit ;p
And apply for full project access (http://drupal.org/node/1562530). Even if not approved, it has been in the sandbox.

If someone useful, give it a try. At the time, support 6.x only.

Thanks.

alan d.’s picture

Hipfox, I'm more than happy for you to help with Webform Share. It sounds like it does what is requested here, although I haven't read in detail the request nor patch.