Download & Extend

Webform Submission with "add another" text field

Project:Webform
Version:6.x-3.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I tried to find some discussion of this functionality, but could not make this happen with either Webform or by modifying the webform with CCK (the custom CCK shows up as a field on the webform creation page, not as something to add as a component that the webform user submits). So is there a way to have multiple text fields become available to the person who submits a webform? Add another "field" on submission of the webform?

Comments

#1

Ever succeeded in doing so?

Cheers

#2

I haven't tried with the latest versions of Webform, but I have never successfully done this.

#3

alright thanx!

#4

Version:5.x-2.3»

Quicksketch,

I came here to see if there as any news on this but I guess there isn't.

Isn't the feature requested possible at all? Or is it something you're not willing to look into?
It would be brilliant to have an 'add another item' option for an input or maybe even a fieldset with multiple inputs inside it.

I guess backendwise it would be harder to fix this as to serialize the data for such an input would render many functions useless but I would love to see this feature so much. And others with me (marked some posts as duplicate).

What's your opinion Quicksketch?

Cheers

#5

I think it would be great too.

Regards.

#6

Is there any news on this subject? I have searched the whole internet I think, but can't find any solution... Anyone??

#7

No, there is no progress on this subject. The ability to support multiple values requires a tremendous amount of re-architecting, including changes to the way CSVs are generated, analysis, the database structure, and the UI (both for administrators and users). I wouldn't expect this feature to be added any time soon.

#8

Is there another solution, in another module? I cannot find such a thing like this in a module for Drupal :(

#9

The only option I can think of is to use some jquery.

- First you create, let's say, 10 input fields in webform.
- You hide input #2 thru #10 by css
- Insert a button 'add another' with jquery
- And then .show() #2 thru #10 when one clicks 'add another'

Downside is that you have quite a bit of setting up to do in webform and that it's not really unlimited. It's basically limited by you webform setup stamina :)

Cheers

#10

Thought of that, but it ain't unlimited indeed :)
With content type fields this is possible, but then every webform submission will become a node. Perhaps that will be the better solution, because it should be really unlimited.

#11

CCK fields would be your only option if it really has to be unlimited... or creating a custom module.
Why is it a problem that every submission will become a node?

Cheers

#12

Thought that could be a problem :)
Trying using nodes and CCK now!

Thanks for replying! Will post here if i'm ready!

#13

#14

Version:» 6.x-2.9

I need this functionality too, but even a little more complicated. Imagine someone is entering CDs and each CD has a title, artist and songs. I would like them to be able to add another CD or add another song. Any ideas?

#15

Version:6.x-2.9» 6.x-3.x-dev

Moving this back into the 3.x branch (issues all lost lost their 3.x versions when I branched for Drupal 7). The trouble with anything like this is that there is a lot more to Webform than just collecting the information. We need to update the analysis, table display, CSV downloads, and other areas to support such things. In Webform 3, I'd suggest making your own component. Either way this would require a significant amount of effort.

#16

This would be fantastic for many reasons!

#17

Would you do it for a Klondike bar?

All jokes aside, that would be a wonderful feature to have. We will keep the hope alive...

#18

subscribing

#19

+1 subscribing

#20

I'll weigh in here to say that #9 @Bartezz above had a clever solution. Depending on your needs, my planned a-hack on this for my simple "order system" is to dynamically build a row of non-webform form fields (partno, desc?, qty, Add Row) which, upon submission of the form, concatenates these form fields' values into a hidden webform textarea: not beautiful, but gets it done in my use case.

If you're interested, stay tuned! It's just crazy enough, it might work..

-Bronius

#21

Subscribing

#22

Subscribing

#23

Subscribe.

#24

#25

A multigroup function similar to that of CCK's multigroup would be ideal. I need individuals to be able to submit table - like data via email and not necessairly have the data stored on the server the way CCK does.

I am including this apparently redundant post because the word multigroup does not appear in it at all and therefore when seaching the issue queue for this issue it did not appear in the search results.

#26

Subscribing.
PS L O V E webform!

#27

subscribe

#28

really need it at this point
Subscribing

#29

Guess that 'at this point' there still is no solution other than the ones given above.
Don't think quicksketch is likely to develop such a feature because we 'need it', it's rather complicated as described above!

Cheers

#30

If anybody knows how to achieve this functionality, either via webforms, or another module, or by writing it from scratch, I'd be very, VERY grateful to hear it. I'd love this functionality to be implemented, but since it's not, at least currently, I'm needing suggestions for alternate solutions.

For example, any information on how a solution as described in #20 could be made would be of great use.

#31

Darkplek,

Quick reply;
- add a hidden field to your webform
- use hook_form_alter in a custom module to add the non-webform field(s) to the webform
- use drupal_add_js in a custom module to add jquery magic to the webform
- through that jquery the user can clone the non-webform fields as many times as he/she needs it
- bind a function to the webform submit button that reads all the data from the cloned non-webform fields and inserts this list of data into the hidden webform field

Cheers

#32

Thanks for your input Bartezz, I'm also looking to do this. I will post back my code if any of it can be used when I'm finished.

#33

I had 10 fields in the fieldset that I need to be able to show to the user on demand.

Heres my javascript that i added to a file to add fields and then take their data and put it in a textarea which is set to display none. This solution turned out uglier than I had hoped and made it very hard to get at the data submitted without writing som PHP to go with it.

In the end I went with a solution where I added 20 fieldgroups to the webform itself within a wrapper fieldset to be able to target the children, all fieldsets containing my 10 fields, and then I used the second script to hide them all except the first one, add a button to display another fieldset etc. Since the adding and hiding is all done with scripting, all fields will be displayed to a user without JavaScript enabled which is a good thing.

// Removed first script, it was to ugly

And I ended up with:

// This is cleaner although not clean
(function ($) {
  Drupal.behaviors.[THEMENAME] = {
    attach: function(context, settings) {
     var i = 0;
     $('#webform-component-objectwrapper'). // Get the wrapper, change the ID to suit your needs
      append('<button id="add-object-button">Lägg till lägenhet</button>'). // Add button, change text to suit your needs
      find('fieldset:not(:first)'). // Hide all but first fieldset
      hide();
     
      $('#add-object-button').click(function() { // When button is clicked and it's not the last fieldset out of 20 to be displayed
        if(i < 20) {
          $('#webform-component-objectwrapper fieldset:not(:visible):first').fadeIn(); // Show the fieldset, remember to change the ID
          if(i == 18) {
            $(this).hide(); // Hide the button
          }
        }
        i++;
        return false; // Prevent submission
      });
     
    }
  };
})(jQuery);

#34

@span; Ah this a solution based on my comment in #9, nice. Thanx for sharing, hope it helps others.
Let's hope Darkplek works out a solution based on #31 and shares it as well :)

Cheers

#35

I've added the code fromn #33 as suggested (using drupal_add_js and referring a file). However, I get "This is not a function" from Firebug when trying to do so and things don't work as expected. [themename] was changed to the name of my theme too.

#36

I highly recommend the in-dev version of the module field collection, you can do all you want to above using nodes. Check it out, http://drupal.org/project/field_collection

#37

+1 subscribing..

#38

I see I neglected to followup with my own jquery hack proposed in #20 above. It ended up being really inelegant, and the results are, after all, crammed into a TEXT fields in the database with built-in delimiters to boot. What is this, a backward IBM Universe Multivalue DB? Yikes-- no thanks.

Sorry not to be of any more help here.. I can see quicksketch's point and that webform is not architected for this. So I wanted to further the discussion of, potentially, a non-webform solution: has anyone taken this to g.d.o yet? I would like to talk about "anonymous can post a cck/entity and then any number of nodereferenced subitems." We would obviously miss out on all the cool webform survey results, but Views could be whipped together, right?

#39

Subscribe

This feature would make Webform uberawesome.

#40

@span Thanks for your code however it caused an error when I used it. My fix was to remove the object with the 'attach' function and assign the function directly to Drupal.behaviors.["THEMENAME"]. Here is my code with some changes:

  • Edit: Allows you to specify how many should be shown initially
  • You don't have to provide the number of fieldsets. It performs the count.
  • Adds protection against nested fieldsets, so even if you have "fieldset > fieldset", only the top level of fieldsets will be affected
  • The function can easily be reused on more than one repeatable component

(function ($) {

Drupal.behaviors['YOURTHEME'] = function(context, settings) {

function fieldsetRepeater(container, fieldsetSelecter, addBtnTxt, numberFirstShown) {
var addBtn = $('<input type="button" />').val(addBtnTxt).click(function() {
var hiddenFieldsets = fieldsets.not(':visible');

hiddenFieldsets.filter(':first').fadeIn();
if(hiddenFieldsets .size() < 2) {
addBtn.hide();
}
});

var fieldsets = container.find(fieldsetSelecter)
.not(container.find(fieldsetSelecter+' '+fieldsetSelecter))
.hide();

fieldsets.filter(':last').after($('<div/>').append(addBtn))

for( var i = 0; i < numberFirstShown; i++ ) {
addBtn.click();
}
}

//Shows one apple initially
fieldsetRepeater($('#webform-component-apples'), 'fieldset', "Add an Apple", 1);

//Shows no oranges initially. Button must be clicked.
fieldsetRepeater($('#webform-component-oranges'), 'fieldset', "Add an Orange", 0);

};

})(jQuery);

#41

Hello,

The button to append a new fieldset doesn't appear. The Js script is loaded, but there is no action on my container #webform-component-MINE.

Do we have to create e.g 10 fieldsets, hide all except the first one ?

Thx a lot.

#42

Should be standard functionality in Webform. Subscribing.

#43

@ain: Use the "Follow" link at the top of the page instead of subscribing.

#44

+1 for the patch approach in #40.

Note for anyone implementing, I got this to work perfectly with a selector like this:

fieldsetRepeater($('#webform-client-form-18'), '.webform-component-fieldset', "Add another", 1);

#45

sorry John but I am new at this. kindly tell me where to insert the code.

#46

Subscribing

#47

Shimba, you will need to create a new JS file like in #40 and then include it on the page(s) you want. There are a few different ways to do this (via custom module, your theme, etc) that are really beyond the scope of this thread. If you are really stuck, email me with your drupal version, the node ID for the webform, and I'll whip you up a small module later this week.

#48

Got a few emails about this, created a small module Webform Add More based on approach and code provided by span and kranklin. All credit goes to them.

#49

Nice one John Money!

#50

Nice work John! And thanx for the credits :p hehehe

Cheers

#51

Ouch! Sorry I missed you in credits Bartezz. Fixing on project page.

#52

Cheers :)

nobody click here