May 30, 2014

Passing Data From one Form to Another using Gravity Forms

A client needed to have a form which will do the following - Have visitors to their site take out an annual membership with the choice to automatically renew at the end of the year long subscription period, as well as have them donate to one of two donation possibilities - a scholarship fund or a protection fund.

After checking with PayPal support it seemed that at least for the moment this would not be possible to do with one button, and since Gravity Forms with the PayPal add-on can only do what the PayPal api calls for, it seemed likely that at least one button would be needed for any subscription type of payment ( the annual renewal of membership), another button for just the regular membership, and another button for donations.

That's a lot of buttons and a lot of forms to hold them, if you are just using a PayPal created button, as well as having to hack the button code to create a proper form with proper redirection for all those myriad cases.

It is likely that some of those things could be embedded in a PayPal button, but it would be unwieldy, and take more time than its worth, especially since Gravity Forms with the PayPal standard add-on could handle a lot of the load.

To do the above, i created two forms, one to handle the annual membership with the possibility of automatic renewal, and another one to create the donations.
The trick was to be able to have the user while filling out the first form and making their choices, that if they decided not only would they like to join (membership) or do the automatic renewal, at that point they could also choose to donate. If they said No then after payment they would be taken to a normal confirmation page, with a thank you for their support, whereas if they said Yes to donate, they would be taken to the donate page, with their name, address and other information already filled out.
To do that data transfer i created  a PhP file to do the data transfer using the query string sent by the first form, and pass it to the donation form if needed, or just redirect to the thank you page.

That file ( called thankyouredirect.php ) looks like this:

ob_start ();
if( isset( $_GET['Donate'] ) ) {
$donate = $_GET['Donate'];
else  $donate = "No";

if( isset( $_GET['First'] ) ) {
$First = $_GET['First'];
else  $First = "firsname";

if( isset( $_GET['Last'] ) ) {
$Last = $_GET['Last'];
else $Last = "Lastname";

if( isset( $_GET['Email'] ) ) {
$Email = $_GET['Email'];
else $Email = "Email";

if( isset( $_GET['StreetAddress'] ) ) {
$StreetAddress = $_GET['StreetAddress'];
else $StreetAddress = "StreetAddress";

if( isset( $_GET['City'] ) ) {
$City = $_GET['City'];
else $City = "City";

if( isset( $_GET['State'] ) ) {
$State = $_GET['State'];
else $State = "State";

if( isset( $_GET['zip'] ) ) {
$Zip = $_GET['zip'];
else $Zip = "Zip";

switch ($donate)

case "No":


case "Yes":
$location =  "Location:$First&Last=$Last&Email=$Email&StreetAddress=$StreetAddress&City=$City&State=$State&zip=$Zip";
header( $location );




This file is called by the first form after it has been filled out and submitted. Once you create a form you can go to the confirmation setting and either have it go to a page or a url, in this case the backend of the first form setting looks like this...note the Donate choice ( radio box on the form)  at the bottom of the merge tags.




Note that the field names and their values that are placed on the second form ( donation form) are  sent by a query string, and that the field name parameters appear in the query string on the left side of the equal sign, while gravity form figures out their value ( the right side of the query string. Using the merge helper ( the upper right small box) really helps decode the form for you, so its simply a matter of making sure you have the correct parameter field name on the left side of the equal sign.

An example of a field that is going to be filled dynamically on the donation page is the Name Field. It holds the first and last names. On that second form (donation form, the advanced tab of the field holds the setting for the parameter names, when they are passed to it dynamically ie;


The PhP file takes a switch for the value of the Donate radio button ( Yes or No) and redirects using the header Location command. But it could easily have taken the value of any of a number of choices from the form and used those choices accordingly.

You could have many different choices on the form, and use this method to create many different outcomes.

I haven't described how the first form handles the choice of membership versus subscription but if you know the PayPal add-on you realize that each of those choices can be handled with a conditional on the form, with a 'PayPal Feed' for each type.  On the form I set up a radio button to ask if they want to do automatic renewal - on the backend of the form it looks like this


If this field is exposed on the form the PayPal feed ( you setup a feed, using subscription type, using this form, by going to the PayPal  addon under Forms ) will act like a subscription type of button, when you go to PayPal to pay.

I set up another  Feed using the other choice ( one year membership) so it works basically the same way, except the feed is a different type ( not a subscription type).



After they choose one or the other between Membership ( one year, or auto renewal) they also choose to donate or not. After submit of the form, the payer will go to PayPal, make their payment, and return with the query string, to the PhP file, which carries the query string to either the donation form or a simple thank you page. The donation form will be filled out with the data, and that form has its own choices of donation, with another payment to be made.

This makes it easier on the coder, the visitor, and is easier to manage than PayPal buttons themselves. The data is collected in the WordPress database ( names and emails), making it exportable to excel sheets or constant contact lists.

Latest posts by Edward Rosenthal (see all)
Latest posts by ed rosenthal (see all)

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    HSS - specializing  in Law, Art, Author, Professional and Non Profit Websites - We'd love to help you -  Building websites since 2001
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram