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 numbers from number field in form submissions?

  1. agelfand
    Member

    I want to have a form that includes a number field. Then, I want to be able to loop through all submissions to this form, grab the value of the number field in each submission, add them up, and echo the total somewhere on my site.

    So if the form was submitted twice, and the first time someone put a 4 in the number field, and the second time someone put a 7 in the number field, I would want to echo "11".

    I'm afraid I do not have a web page to reference - this is a feature a client requested recently, and I haven't been able to find the answer on the forums so far. Any advice? Thanks!

    Posted 14 years ago on Tuesday November 30, 2010 | Permalink
  2. Hi Agelfand,

    Here is a quick little function that will let you do this for most GF fields (you'll run into issues if trying to access fields with floats for IDs):

    http://pastie.org/1336369

    The first parameter is the form id of the form the field is contained in. The second parameter is the field id of the field you want to calculate the total for. You can output this total like so:

    echo gf_get_field_sum(1,4)

    Posted 14 years ago on Tuesday November 30, 2010 | Permalink
  3. agelfand
    Member

    Works like a charm! Thanks so much for the quick response.

    Posted 14 years ago on Tuesday November 30, 2010 | Permalink

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