I'd love to be able to create a webform to poll users of amounts they spend at an event and have webform automatically calculate averages AND totals spend from each field on the webform.

I don't even see there is an option for an integer field...just a 'textfield' which people could enter text...or the $ sign which would mess up the output. I thought it'd be much like the cck fields where you could create an integer field and set a prefix (the $ sign).

Is this possible?

Comments

quicksketch’s picture

Status: Active » Closed (fixed)

You've been able to create a prefix on fields since 2.1. Webform however has no support for type-cast fields (like integer, text, decimal, etc). Since this is such an old request, I'm going to go ahead and close. Please reopen if you have further questions on this subject.

mdowsett’s picture

Version: 6.x-2.x-dev » 5.x-2.1.3
Category: support » feature
Status: Closed (fixed) » Active

I've moved it to a 'feature request' as I'd like to see if there is any interest in making that a reality. And it was my mistake that I had it flagged as a d6 issue.

Does anyone else want auto-calculated stats from submitted webform fields? It seems to me it'd be a handy stat to have.

quicksketch’s picture

I don't think Webform has an existing paradigm for solving this problem. Could you be more descriptive in how you imagine this working? Some problems that will need to be solved: How would webform know what fields it should tally up? Would numeric values have to be enforced in certain fields?

mdowsett’s picture

>How would webform know what fields it should tally up?
>Would numeric values have to be enforced in certain fields?
sure....set a webform field as:
- integer - for straight numbers (no calculation)
- sum - for integers that would be added in the webform results
- average - for integers that would averaged from all submissions in the webform results

In theory, it sounds simple to me...but I am no programmer! :)

mandclu’s picture

Title: integer field & averages/totals » One approach

One approach I took to solving this problem was to create a new field type, called "number". You can download the code I've been using here:
http://drupal.org/node/260708

For the record, it allows you to specify whether the field should accept an integer or a float (decimal), and whether the analysis page should show an average or a sum.

Give it a whirl, it sounds like it should do what you need.

mandclu’s picture

Title: One approach » integer field & averages/totals

Sorry, didn't mean to change the title of the thread.

quicksketch’s picture

Status: Active » Closed (duplicate)
j3rry’s picture

use the module http://drupal.org/project/webform_validation
and use regex.