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.

Adding two values in user notification shortcode

  1. I have multiple instances where I need to add the value of two fields and then apply conditional logic to that value in my user notification, see below:

    [gravityforms action="conditional" merge_tag="{Are You Married?:55} + {How many children reside with you?:19}" condition="is" value="3"]
    Married with one kid

    NOTE: The "Are you married" field is a dropdown. If yes is selected, it returns a value of 2, no returns a value of 1

    The above didn't can I make that happen?

    Posted 7 years ago on Saturday July 14, 2012 | Permalink
  2. David Peralty

    Unfortunately, conditional logic doesn't allow those kinds of things yet. You would have to create hidden fields in your form, and then using the gform_pre_submission hook, you would have to write a function to do the logic, put a value in your hidden field, and then use conditional logic to pick up on that.

    So for your example, you would have a hidden field called "lifestatus".

    Your pre_submission hook would grab the submitted values from your two fields, do the math, and send the value back to the lifestatus field.

    Then your conditional logic in your notifications would be able to do the is 3 conditional to show Married with one kid.

    Posted 7 years ago on Monday July 16, 2012 | Permalink
  3. Thanks. Any code examples available using the presubmission_hook? Chances are I'll have to hire someone to set that up but would like to give it a whirl first.

    Posted 7 years ago on Monday July 16, 2012 | Permalink
  4. David Peralty

    Check out our documentation here:

    So you would want to grab the values from two form fields, add them together, and assign them to a third hidden field that you would then test again in your conditional shortcode in your notifications.

    Posted 7 years ago on Monday July 16, 2012 | Permalink
  5. Worked perfectly...thanks!

    add_action("gform_pre_submission", "pre_submission_handler");
    function pre_submission_handler($form){
        $married = $_POST["input_55"];
    	$kids    = $_POST["input_19"];
        //Hidden Field
        $_POST["input_57"] = $married + $kids;

    The notification conditional statement

    [gravityforms action="conditional" merge_tag="{means total:57}" condition="is" value="3"]
    Married with one kid
    Posted 7 years ago on Monday July 16, 2012 | Permalink
  6. David Peralty

    Glad to hear it, and thanks for posting your code. I am sure it will help others.

    Posted 7 years ago on Monday July 16, 2012 | Permalink

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