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.

mathematics to gravity forms

  1. Hello,

    Is it possible to use mathematic formulas within gravity forms?

    With Regards,
    Martin

    Posted 12 years ago on Friday June 10, 2011 | Permalink
  2. Gravity Forms only does Pricing calculations on the Pricing fields. It does not do mathematic formulas on other fields, only price calculations. Generic calculations is a feature we'd like to introduce in a future release.

    Posted 12 years ago on Friday June 10, 2011 | Permalink
  3. RTM
    Member

    I'm creating a form that requires users to answer a series of questions, each with a numerical value. They get a score based on the sum of these questions/values. Since there is no ability to do mathematical formulas, do you have any suggestions for a work-around? Thanks.

    Posted 12 years ago on Saturday August 13, 2011 | Permalink
  4. Please post more information about your set up. It is possible to do but will require some customization, so it makes sense to work with your actual scenario. Please post part of what the form will look like, what the values will look like, and what you would like to do with the score once you have it. Thanks.

    Posted 12 years ago on Sunday August 14, 2011 | Permalink
  5. RTM
    Member

    Chris, as you know Gravity Forms gives you the ability to assign a value to a field. At a macro level, I'm just trying to figure out how to do something with those values.

    For example, assume a 20 question medical survey where Yes = 1 and No = 0. How do I total up my "Yes" answers? I need to know their total score to indicate their risk of (enter disease here).

    - Patients with 15+ points have high risk.
    - Patients with 5 to 15 points are at moderate risk.
    - Patients with 0 to 5 points have no risk.

    Posted 12 years ago on Sunday August 14, 2011 | Permalink
  6. Got it; I think I understand what you're looking for. I will work something up for you tonight and post it here by tomorrow morning.

    Posted 12 years ago on Sunday August 14, 2011 | Permalink
  7. RTM, sorry I did not get to post this earlier. Here is the code: http://pastebin.com/uz7VX2NP

    Here is an XML export of the form. http://gravity.chrishajer.com/wp-content/uploads/gravity_forms/8/leadership-quiz.xml

    You can save that XML and import it into your site to see how it works.

    I added one hidden field (Score, field 25) and one admin only field (Rating, field 24). Initially, they were both admin only but there is a problem storing 0 as the value in an admin only field, so I had to switch it to hidden. The Rating field is a paragraph.

    There is a loop in there from 1 to 20, to go through all the radio buttons. My questions were fields 1 through 20 in the form, which made it convenient. Yours could be different, but they need to be sequential to use the loop like this. If yours go from field 5 to 24 (for example), just change the loop.

    Let me know if you need more explanation or help implementing that.

    Oh, also, the quiz came from here:
    http://www.wishner.com/PDFs/WishnerLeadershipQuiz.pdf

    And you can see a working example here:
    http://gravity.chrishajer.com/leadership-iq-test/

    Posted 12 years ago on Monday August 15, 2011 | Permalink
  8. Art Gross
    Member

    Chris - I am looking to do almost the exact same thing as your example. My question is this: Where do I paste the code that you wrote ( http://pastebin.com/uz7VX2NP ) ? I tried to paste it in the functions.php file but every time I do it stops my website from running. Any additional insight would be appreciated.

    Posted 12 years ago on Saturday August 20, 2011 | Permalink
  9. If it stops your site from functioning with a white screen, you've pasted it in the wrong place. It need to be inside <?php tags. Sounds like you pasted it in AFTER the closing ?>. If so, just paste it right before that closing tag.

    If you want a suggestion on where to place it, post your complete functions.php to pastie.org or pastebin.com and we'll help you get it in the right spot.

    Posted 12 years ago on Saturday August 20, 2011 | Permalink
  10. Chris,

    I know some time has elapsed since you last responded to this post, but I was hoping to get your thoughts on something of an extension of this example. I have a pretty basic quiz (30-questions) with each item on the quiz having a possible value between 1 and 10. What I'd like to do is to use a required numeric (number field) to capture the totals. Currently I have the quiz paginated (10 questions per section) but it doesn't have to be that way, and my goal would be to provide a section score and an aggregate score. The end-user then can (manually) compare against a range to see how they stack up (e.g. you scored 250, see the chart below to see what this means - ideally I'd do that programmatically as well - and it looks like your logic would get me most of the way, but with a possible scoring range between 30 and 300, it could be a pretty daunting task to write the case logic, at least the way you have it in your code. Any thoughts or ideas?

    Thanks

    Posted 12 years ago on Tuesday September 13, 2011 | Permalink
  11. Trying to do something similar. Simple 5 question form where radio button values are between 1-10. I then want to publish the average score from those 5 questions. Trial and error is frustrating when your PHP skills are limited but I appreciate Chris' example as its a good starting point.

    Posted 12 years ago on Tuesday September 13, 2011 | Permalink
  12. Altitude Marketing, if you've already purchased Gravity Forms, we'll be happy to help you with your customization request in your own support topic. We try not to handle support requests in the pre-sales forum, but I previously failed at that here.

    Tremolo, please start a new support topic with your question and reference this post if you like. Thank you.

    Posted 12 years ago on Tuesday September 13, 2011 | Permalink

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