Please Note: We are no longer using forums to facilitate standard support. 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.

Counting responses

  1. gwc_wd
    Member

    My need is not standard for GF so I am looking for any input from the community on how I might achieve it -- no expectations.

    It is similar to
    http://www.gravityhelp.com/forums/topic/is-it-possible-to-tabulate-the-responses-to-a-form

    Here is what I want to do:

    What colour would you like the living room: a) blue b) green c) red
    What colour would you like the kitchen: a) blue b) green c) red
    and so on....

    Then I want the results to show

    You chose:
    Blue: 7 times
    Green: 3 times
    Red: 1 times
    
    You are mainly a Blue person.

    The last bit I think I could work out with Chris Hajer's code:
    http://www.gravityhelp.com/forums/topic/making-a-result-page-based-on-conditional-logic

    I have tried a number of approaches including turning "blue" into a product with a $1 price, but of course there is no subtotal field for separate products. Thought of using Options then Conditional the Total on the option, but it doesn't really work either.

    My first thought was that this has to be easier than it appears because it is after all just counting. My problem is that I can't count my nose using Select statements and PHP which is what I'm guessing is required here. I'm thinking if I had the right code I could put it into an HTML field which could then be presented in a Post Body template.

    But then, my last thought is that it must be much more difficult than it seems since none of the poll or voting plugins I've found will do this either.

    Posted 3 years ago on Friday September 2, 2011 | Permalink
  2. This post is probably closest to what you want.
    http://www.gravityhelp.com/forums/topic/mathematics-to-gravity-forms#post-32566

    But there, I am just totaling up the correct answers (so I can use 0 as the value for a wrong answer, and 1 for the value of a correct answer, and just add up all 20 values to arrive at a total number of correct answers.) Here, you need to do something slightly different. You want to count the total number of times each answer is given (so, number of blue, number of green, number of red.)

    Do you have 10 questions, and each question can only have one of three possible colors, or was that a simplified example? Please post exactly what you need to accomplish and I can work up an example for you.

    Posted 3 years ago on Friday September 2, 2011 | Permalink
  3. gwc_wd
    Member

    You do see the difference in what I am trying to do precisely - the total number of times a particular answer is given.

    It was a simplified example, but does reflect almost exactly what I want.

    It is simplified in that my application would have five to ten characteristics rather than 3 colours. The characteristics are not directly selected, but a Value is assigned.

    So this would be what the form would show - multiple choice field with Values

    'In my kitchen I prefer
    to feel like I'm on the ocean -- value blue
    a clean no-nonsense environment -- value white
    intensity and creativity -- value red'

    There might be many other questions with these red, white, red or other values.

    I want to total the number of times each value was selected.

    Is that a clearer explanation?

    The components really are arbitrary. It's just a paired list of statements and values.

    Posted 3 years ago on Friday September 2, 2011 | Permalink
  4. gwc_wd
    Member

    I just went over your code. http://pastebin.com/uz7VX2NP

    It is certainly getting me trying to learn to code because it feels like it's right there.

    I need operations to count each Case.
    So would it be like this:

    switch($valuename) {
                    case red: $redcount++
                    case blue: $bluecount++

    I have to tell you I am learning a lot from your help here and to others. For an old guy (me), that's a great thing, so thank you!

    Posted 3 years ago on Friday September 2, 2011 | Permalink
  5. So, did you figure it out, or do you need additional help? I couldn't tell from your last message if the issue was totally resolved. I hope it is and we're on the same page now. I see how you're using questions and the answers will use colors as values, which you will count.

    Will there possibly be an unknown number of values (so, maybe more than a fixed number of colors? Maybe there are 6 colors, but tomorrow you find a new question and have to add purple or something?

    Posted 3 years ago on Friday September 2, 2011 | Permalink
  6. I'm also trying to do the same thing as <b>gwc_wd</b>. I need to total the number of times a value is selected and then show a confirmation message based on the winning value. Make sense? Help anyone?

    Posted 3 years ago on Thursday December 8, 2011 | Permalink
  7. Hi CW,

    This hook is a good place to start:

    http://www.gravityhelp.com/documentation/page/Gform_confirmation

    This hook passes the $entry which contains all of the selected values. You can loop through these values and tally up the totals, displaying the appropriate message depending on the outcome.

    Posted 3 years ago on Thursday December 8, 2011 | Permalink
  8. David-

    Thanks! That solves my problem for the confirmation message, but still having a hard time wrapping my head around how to total the winning value. Any ideas? I'm interested in having 3 types of emotions. Each emotion would have a value, say - happy, mad, and sad. If I have 10 questions, I want to total the amount of times each emotion is selected and then display the winning emotion and message. Please help!

    Posted 3 years ago on Friday December 9, 2011 | Permalink
  9. Hi CW,

    Here is a working example:

    http://pastie.org/2993675

    Just paste it in your theme's functions.php and update as needed.

    Posted 3 years ago on Friday December 9, 2011 | Permalink
  10. YOU ROCK! Just tested your code and it works beautifully (as long as you have more questions than moods). :) I think others will be happy, as well. I've seen several questions on this topic. Thanks again.

    Posted 3 years ago on Saturday December 10, 2011 | Permalink
  11. Glad to hear. :)

    I'm going to go ahead and close this topic; but if you have any other questions on this please feel free to create a new topic and reference this one. :)

    Posted 3 years ago on Saturday December 10, 2011 | Permalink

This topic has been resolved and has been closed to new replies.

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only