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.

Form displays calculation results

  1. I have tried to use this example ( and create a form that basically does a small calculation but cannot get it to work.

    Here is my code

    add_action("gform_post_submission_8", "calculate_savings", 10, 2);
    function calculate_savings($entry, $form){
    	$savings = $entry['1'] - 100;
    	$_POST['input_2'] = $savings;
            return $form;

    POST['input_2'] is a hidden field in the form which I then insert in the confirmation message for the user to see.

    $entry['1'] is basically a numeric field which I then use to calculate.

    Any help would be appreciated

    Posted 12 years ago on Friday August 26, 2011 | Permalink
  2. What happens now when this runs? Does any value come back or is it always -100 or something?

    Also, I think you are going to run into problems because you are running this "post_submission" which is after the entry is created. So, you will not be able to insert this into input_2 since the entry is already created.

    Are you just trying to take a number they submit, and show them a savings of 100 in the confirmation text (not an email, just the displayed confirmation message)?

    Posted 12 years ago on Saturday August 27, 2011 | Permalink
  3. At the moment no value is returned. Thanks for the heads up regarding the use of "post_submission". What do you recommend I use?

    Yes I just want to use the number that the user submits, do some simple calculations based on that number and return the result to the user via the displayed confirmation message. I might not even save in the database as well.

    Posted 12 years ago on Monday August 29, 2011 | Permalink
  4. Hi x2gravity,

    Give this a shot:

    The issue was you were updating the $_POST after Gravity Forms has already processed the entry and retrieved all the values from the $_POST. By using the gform_pre_submission hook, we can add the $savings value to the "Savings" field $_POST before Gravity Forms processes the entry so the new value will be processed.

    You can access the saved value using the token; something like {Field Name:field_id} ~ {Savings:2}. You can get the actual token from the drop down on the confirmation message and add it anywhere in the message.

    Posted 12 years ago on Monday August 29, 2011 | Permalink
  5. Worked perfectly

    Can you tell me what rgpost does?
    Thanks again

    Posted 12 years ago on Monday August 29, 2011 | Permalink
  6. rgpost() is a "safe" way to retrieve values from the $_POST global. It automatically checks to see if the requested index/key exists in the $_POST global before attempting to access that index/key to prevent undefined index notices.

    Posted 12 years ago on Monday August 29, 2011 | Permalink