1

First-timer here, a little background: I'm a pretty seasoned builder using tons of modules, but not a developer. Want to start diving into PHP-coding, just not that far yet. Please keep that in mind if you'd be so kind to answer... For now, there's something I want done.

I use the Webforms-module to gather registrations for an event. One of the fields on the form is numerical and holds the amount of persons registering. Works great. Webform gives me a nice analysis in which the submitted values for this field are summed, so I can easily see how many people to expect.

Now I want to use this summed value somewhere else as well. For instance on a page that is accessible by non-authenticated users (as opposed to the Webforms results view, that contains all the personal data I do not want to be public). So I need either some token that I can use elsewhere on the site, or another way of programmatically incorporating that value in a block or a node. Did my share of searching and found a lot, but nothing useful.

I just learned from Klaus Harris' blog how to write a very basic module that can show a page. But how do I get this piece of data where I want it? I took a peek in the webform.report.inc-file that's part of the module, but was rather intimidated by what I saw there...

Is there some way to do this that I can handle without first graduating as a Drupal developer? Or is this too big a jump?

  • you can use Views to create a block and sum up all values of your field by using aggregation(SUM). Are you familiar with Views module? P.S. You will be able to use Views without writing any code. – oksana-c Jan 9 '16 at 11:13
  • @oksana-c: Good idea, yes, I know how to work with Views so I tried your suggestion. Problem: the webform's fields do not show in the list of fields that can be added to a view. Just like they're not part of the form as it appears in the Content Type. When adding a field to a view, I cannot find the field that contains the filled in amount of persons. Neither under Content:, nor under Webform:. There is a counter for the number of submitted forms, but that's not what i need. – Rob Vermeulen Jan 9 '16 at 12:47
  • Did some more research on this. It seems indeed an accepted (but often regretted) fact that webform elements are not fieldable, an thus cannot be used als fields, filters or sort criteria in views. – Rob Vermeulen Jan 9 '16 at 14:57
  • not true, I'm adding an answer with detailed instruction on how to do what you wanted right now. Give a minute or two. – oksana-c Jan 9 '16 at 15:06
0

It is kind of confusing to create Webform Views with aggregation at first, I'll try to give a detailed explanation.
First, you would create a View of "Webform Submissions" - use unformatted list of fields as format.

Remove all fields that are placed in your View by default.

Add relationship to "Webform Submissions: Data" as shown the screenshot below. Adding relationship to webform submission data is crucial for Summing up your field values, because the added relationship gives you an option to add raw value of your field to the View (otherwise SUM aggregation doesnt work - see here). So, you would select your Webform node by typing its ID or the Name of your form, then in "Component Data" drop-down you'll select the field which stores the number that you need to sum up.

enter image description here

Add the field to the View scope: Select "Webform submission data: Numeric value(raw)", or " *: Value(raw)". They both will produce the result that you want. Make sure you select the relationship that you added previously in the field relationship drop-down.

enter image description here

Enable Aggregation for your View and set Aggregation to "SUM" on the your numeric field. Watch your field result summed up.

See if this approach works for you.

  • Thanks, you did a lot of work! Tried to follow your directions, but when adding the relationship I can only enter the Identifier. The 'Webform node' and 'Component data' fields are not there! – Rob Vermeulen Jan 9 '16 at 15:26
  • Sorry, running out of time now since I also do cooking and guests will arrive soon. I'll be back, but thanks for now! – Rob Vermeulen Jan 9 '16 at 15:27
  • Views integration of webform_submitted_data table was introduced in Webform 4.x and as far as I know wasn't back-ported to previous versions. What version of Webform are you using? – oksana-c Jan 10 '16 at 16:48
  • I had a 3.x version of Webform, updated to 4.12 now. But still I don't get the 'Webform node' and 'Component data' fields. What item should I choose in the first list I get when adding a relationship? – Rob Vermeulen Jan 11 '16 at 10:25
  • As mentioned above - Add relationship to "Webform Submissions: Data". – oksana-c Jan 11 '16 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.