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.

Carry the Total from one form to the next

  1. I have a series of hot lunch order forms I'm building for my son's school. I wasn't able to find a solution in any shopping cart plug-in, as the order forms are complex. Gravity Forms seems like the perfect option, except I need to amalgamate a few orders into one payment...

    Each family needs to fill in three order forms for each order period (eg. one for March, one for April and one for May). I'd like to carry the order total from one form to the next to the next, so at the end I can carry it to Paypal via the Paypal Add-On, instead of having parents go to Paypal three times per kid.

    The following code seems like it's heading in the right direction but I'd really appreciate more specific help with the parameters I would use for Total... http://www.gravityhelp.com/forums/topic/can-conditional-logic-be-used-to-display-a-form-depending-on-another-form

    Also, could I have Total 1 + Total 2 + Total 3 = Total Payable (then to Paypal)? I'm thinking this would use similar parameters as above to dynamically populate Price fields?

    Thanks so much...
    Lindsay

    Posted 12 years ago on Thursday February 16, 2012 | Permalink
  2. Hi, Lindsay,

    What if instead of using separate forms, it was one form with 3 pages (page per month)? This would allow you to have page 1 have the products/quantities for March, page 2 April, page 3 May. Then when you submit the form, the total would cover all 3 months and that would get passed to PayPal as one transaction. You could even do this on one page and just name the products so it is obvious which month they are working with.

    Posted 12 years ago on Monday February 20, 2012 | Permalink
  3. In setting up the forms for the hot lunch orders, I'm trying to get as many families from the school to "buy in" to ordering online instead of keeping the paper forms. The plan is to make the online forms work exactly the same way as the paper forms they have used for years. I will get a lot of push to just offer subtotals -- it seems like it should be simple? I can do all three orders with one form (three pages) or with three forms, that's not the problem really. What's really important is to show a total for each lunch ordered -- a total A, total B and total C (one for each month), then a Grand Total. Can the Total fields be programmed to add up only selected fields? Or is there some other way of doing "subtotals?" I can add code to the functions.php file, but I am not yet successful coming up with the php on my own and would really be grateful if someone could show me very specifically what to do. Again, LOVE Gravity Forms, and I'm very excited to have it to build these forms for the school.
    Lindsay

    Posted 12 years ago on Tuesday February 21, 2012 | Permalink
  4. Hi, Lindsay,

    Here is what you can do. The assumption is four separate forms; one for each month and the final one that lists out the totals of the others with a grand total (this form is the one submitted to PayPal).

    Create your form for March and have a Total field on it. Setup the Confirmation to be a Redirect to the URL for your second form (April) and click the checkbox for "Pass Field Data Via Query String". Select the merge tag for your Total field and name your parameter using the month so you will have something like march_total={Total:1}. This will pass along the total from Form 1 to Form 2.

    Create your Form 2 for April and have a hidden field that will be populated with the total from Form 1. On this hidden field you will go to its Advanced tab and select "Allow field to be populated dynamically" and enter the Parameter Name from the querystring (march_total). This way you have the total from the first form carried over.

    For Form 2, you will setup your confirmation to be a redirect to the URL for your third form (May). You will again click the checkbox for "Pass Field Data Via Query String". This time you will insert the merge tag for your hidden total field for March's total AND then the merge tag for your current form's total (April). So you would have something similar to march_total={March Hidden Total:28}&april_total={Total:5}. These totals will then be passed along to your third form (May).

    For Form 3 (May), you will add two hidden fields that will be populated with the totals from the first two forms. On these hidden fields, you will again go to the Advanced tab and select "Allow field to be populated dynamically" and enter the Parameter Name from the querystring. The Parameter Name will be "march_total" for one of the hidden fields and "april_total" for the other. You will again setup your confirmation with the appropriate merge tags to pass along the totals to the fourth form.

    For Form 4 (final listing of totals), you will now have the totals from the other forms available for use to modify the total passed along to PayPal. For this form you can use the "gform_product_info" hook (http://www.gravityhelp.com/documentation/page/Gform_product_info). You can use this to add your products for March, April, and May with their totals. You can also use the "gform_product_total" hook to populate the total field with the combined totals for each of the months (http://www.gravityhelp.com/documentation/page/Gform_product_total)

    This article may also help you out: http://www.gravityhelp.com/documentation/page/Gravity_Forms_Pricing:_Adding_Tax

    Take a look and let me know if you have questions. I know it is a lot of info at once. :)

    Posted 12 years ago on Wednesday February 22, 2012 | Permalink
  5. Thanks Dana, I just saw your reply. I will see if it would work better than the large form I have - for the next round of hot lunch orders! I'm really looking forward to a Subtotal button and some sort of "shopping cart" or "order summary" features.
    Along these lines, is it possible to have the order summary that shows up on the confirmation page show up before the user submits the order? It seems as though it's within the realms of GF possibility?
    Thanks!
    Lindsay

    Posted 12 years ago on Wednesday March 7, 2012 | Permalink
  6. Hi, Lindsay,

    Yes, you could do this with GF. You could add another page to the form to be the confirmation page. You can gather the information previously entered on the form and display it on this page. You can use the "gform_pre_render" (http://www.gravityhelp.com/documentation/page/Gform_pre_render) hook to achieve this. This hook fires for every page. Below is an example where I have a form with two pages. The second page has an html field that I am populating with information from the first page. Take a look.

    add_filter("gform_pre_render", "populate_welcome");
    function populate_welcome($form)
    {
    	//only get data form form id 31
    	if ($form["id"] == 31)
    	{
    		//check what page you are on
    		$current_page = GFFormDisplay::get_current_page($form["id"]);
    		if ($current_page == 2)
    		{
    			//set the field on page 2 to the first/last name from page 1
    			//get the name
    			$first = rgpost("input_1_3"); //first name field when using the normal name format broken into two fields
    			$last = rgpost("input_1_6"); //last name field when using the normal name format broken into two fields
    			foreach($form["fields"] as &$field)
    			{
    				//html field (id 3) on second page which will display name from first page
    				if ($field["id"] == 3)
    				{
    					$field["content"] = "Welcome, " . $first . " " . $last;
    				}
    			}
    		}
    	}
    	//return altered form so changes are displayed
    	return $form;
    }
    Posted 12 years ago on Friday March 9, 2012 | Permalink
  7. Thanks Dana, I really appreciate the code to do an "order summary" page and will try this in April.
    Cheers!
    Lindsay

    Posted 12 years ago on Sunday April 1, 2012 | Permalink

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