PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Calculate Value for Multiple Choice

  1. sasharr
    Member

    I have a form that has 15 questions and if the user answers yes, the value is 1, if they answer no, the value is 0. I would like the form to sum up all the 1's and give the user their final calculated number after they submit the form, on the confirmation page.

    How can I do this?

    Posted 13 years ago on Wednesday December 1, 2010 | Permalink
  2. Maybe this approach could be adapted?

    http://forum.gravityhelp.com/topic/calculate-numbers-from-number-field-in-form-submissions

    You'd have to do an additional step to assign values of 1 or 0 based on checked or unchecked (or maybe just count the number of checked boxes instead of summing the actual values), but the rest would be the same.

    Posted 13 years ago on Thursday December 2, 2010 | Permalink
  3. sasharr
    Member

    Thanks for the response, but I don't know what the exact code should look like to make this happen. And can it even be posted on a page so that it shows up after the form is submitted?

    If not on a page, where do I post that code?

    I have 15 questions for this quiz.

    Thanks~

    Posted 13 years ago on Thursday December 2, 2010 | Permalink
  4. After rereading and trying to implement this, I realize that the other solution posted by David Smith added up a single value for one field on one form, over multiple submissions (for example, "how many guests will be attending" and then one person submits 7, another submits 4, and you need a total for a party. David's solution answered that question. The sum for entries in that field for one form is 11, in this case.)

    So, your application will require a different approach. Maybe someone else can post a suggestion.

    Posted 13 years ago on Thursday December 2, 2010 | Permalink
  5. I put together a test here:
    http://guitar.chrishajer.com/2010/12/02/sentiment-quiz/

    Here is the code to put into your theme's functions.php:
    http://pastie.org/1342810

    You will need to look at the source of the page with your form embedded to determine the field numbers. I put the 15 fields consecutively, and in my form, there are no other fields. So, my starting field is 1 and ending field is 15. If you have any fields before the 15 yes/no questions, then you will have a different starting and ending field number. Adjust those on line 4 and line 5.

    Also, to ensure this action runs only on the one form, you should change the form number (7 in my example) on line 14 to your actual form number.

    gform_post_submission_7

    Change that 7 to your form number.

    You can change the text that is echo'd on line 11. I included the entry number just to make sure I was doing it correctly.

    I'm not crazy about how the total number of "yes" entries and the confirmation are displayed on the same page, but I think this should get you headed in the right direction.

    Posted 13 years ago on Thursday December 2, 2010 | Permalink