I wanted to show a custom success/confirmation message on the confirmation page after a Gravity Forms submission. But I didn’t know how to grab the parameters in the url.
I found this thread that helped me get started: http://wordpress.stackexchange.com/questions/111376/use-query-string-in-url-to-display-content-on-the-page
1. Choose Confirmation Page and parameter in Gravity Forms
I wanted people to sign up for an account before using the page of multiple visa forms. But I wanted them to be sent directly to that page after signing up. I also wanted to display a Success message on that page, letting them know that the form was successful.
The problem was that current account holders also need to use the page of multiple visa forms, and if they saw the success message, that would be confusing; it might have been years ago that they first signed up.
In other words, all visitors using the page of multiple visa forms should not see any success message, except those visitors being redirected to there after signing up (which is simply submitting a Gravity Form).
To do that, I used Gravity Forms Confirmation Page with parameters. In a form, go to Settings > Confirmations > Default Confirmation. Instead of Text, choose Page, and select the WP Page that you want people to go to after submitting the form. In my case, I wanted people to go to “Select a Visa” after filling out the form “Open an Account.” Check the box for Pass Field Data Via Query String. In the field that appears, enter
parameter=individual_account_success
It doesn’t matter what word you use for “parameter,” but here are some guidelines I found. There may be more:
- whatever word you use, make sure you are consistent wherever I use “parameter” in the following steps. Otherwise it won’t work.
- don’t use the same word as other parameters you may also be including (see Sample below the text field)
- I think capital letters are okay, not sure though
For the parameter value on the right side of the equals (=) sign, you can create your own label there too, even using spaces I think. I used underscores, but I don’t think you have to. There, too, be consistent with your choice in the following steps.
Click Save Confirmation when done.
2. Test confirmation page url
I tested the form, and after I submitted the Open an Account form, it sent me to this url:
http://website.com/select-a-visa?parameter=individual_account_success
So far, so good. Now how to display the confirmation message using that query string?
We use a shortcode.
3. Add shortcode to your theme’s functions.php file.
Here is the code I used:
//* Shortcode to display form success on another page add_shortcode('form_success_message', 'form_message_function'); function form_message_function( $atts ) { extract( shortcode_atts( array( 'message' => '', ), $atts ) ); // Get var from parameter in Gravity Forms confirmation page url $success_message = $_GET[$message]; // this $message word has to be the same as the word in the extract above (but without the $) // you can test with: return $_GET[$message]; if( $success_message == 'individual_account_success' ) { return '<div class="info-box green"><strong>Success!</strong> Thank you for opening an account with ISS. We have received your Scope of Services Agreement. You are all set to initiate a visa petition!</div>'; } if( $success_message == 'corporate_account_success' ) { return '<div class="info-box green"><strong>Thank you!</strong> We have received your Scope of Services Agreement.</div>'; } if( $success_message == 'company_info_success' ) { return '<div class="info-box green"><strong>Success!</strong> Thank you for opening an account with ISS. You are all set to initiate a visa petition!</div>'; } }
This is a more in-depth with all the conditionals, but I’ll explain more later.
4. Display shortcode on confirmation page
Add this shortcode to the top of the confirmation WP page, in my case “Select a Visa” page:
[form_success_message message='parameter']
Success! A message box appears on the Select a Visa page only when the person came there from filling out the Open an Account .
All done, right?
No, because almost everything I build ends up being way more complicated than that. In this case, we had 2 types of accounts, individual and company. Individuals filled out the Open an Account and went straight to Select a Visa. Companies filled out the Open an Account form and were sent to a second form to fill out their Company Information before finally being sent to Select a Visa. Was it possible to send different users to different pages after submission?
Here’s how I did it:
I used 2 confirmations on the same form. (Did you know you can duplicate the Default Confirmation?!). The 2 are Default Confirmation and Company Confirmation.
Default Confirmation is the same as Step 1 above.
Company Confirmation is also a Page confirmation type, but to the Company Information form. The parameter for that confirmation is:
parameter=corporate_account_success
Some fields in Company Information were exactly the same as Open an Account forms, like Company Name, Address, Email, and Phone. Did they have to fill out the same exact information twice?
No, I added those fields to the query string too, so the data string is quite long:
legalname={Legal Name of Organization:1}&address1={Address of Organization (Street Address):5.1}&address2={Address of Organization (Address Line 2):5.2}&city={Address of Organization (City):5.3}&state={Address of Organization (State / Province):5.4}&zip={Address of Organization (ZIP / Postal Code):5.5}&firstname={Your Name (First):2.3}&lastname={Your Name (Last):2.6}&phone={Your Phone:3}&email={Your Email:4}¶meter=corporate_account_success
Gravity Forms gives you a conditional (except for the default confirmation). If users selected the Company terms of service instead of the Individual terms of service, I used this Company Confirmation instead.
On the Company Information page, I added the same shortcode to the top:
[form_success_message message='parameter']
The shortcode itself decides which message to show based on the parameter I set in the Gravity Forms Confirmation query string box.
If you noticed I had 3 conditionals in the shortcode code, the 3rd one was for the success message after a user fills out the Company Information and goes right to the Select a Visa form.
Miguel says
This is the best case study I’ve read about Gravity Forms. Thank you very much for sharing your knowledge. I’m Miguel, Hugs from CUBA!
Sarah Moyer says
Hi Miguel! Thanks so much for taking the time to post on my blog! I’m happy that you found this info helpful 🙂 Greetings in return to Cuba!
Paul says
Hi Sarah, have you found a way to include the users name in the confirmation success message?
Something like:
Success! Thank you for opening an account with ISS, {NAME}. We have received your Scope of Services Agreement. You are all set to initiate a visa petition!
Paul says
All good, found it in the link you shared above. Sorted!
Sarah Moyer says
Sorry for the delay! Glad to hear you found the answer, Paul.
Aarti says
Hi Sarah, I am unable to get the Name from the query string as how Paul mentioned in his question above
Success! Thank you for opening an account with ISS, {NAME}. We have received your Scope of Services Agreement. You are all set to initiate a visa petition!
How to extract Name parameter from the query string to incorporate with the message of Success
Sarah Moyer King says
Aarti, I think Paul mentioned that he found the answer in the link I mentioned, that is: http://wordpress.stackexchange.com/questions/111376/use-query-string-in-url-to-display-content-on-the-page
Have you delved into that?
Hope that helps!
Sarah
Chris Peters says
Very clear and to the point. Sarah this is the best article I found in Gravity Form jungle. May be Gravity Form folks should learn from you on documentation. Thank you so much, was very useful.
Chris
Sarah Moyer says
Wonderful Chris! I’m glad this helped you, too!
Brent says
Great article. Thank you. Any chance you could update screenshots for the latest version? This post will become seminal if maintained. Thanks for doing what GForms could not.
Sarah Moyer King says
Hi Brent! Thanks for the encouragement! I’ll try to keep updates in mind! As of now, I checked and the screenshots still look up to date. I could improve the post though. I find it hard to follow myself. 🙂
Jared says
Thanks, I appreciate the code and walkthrough. It saved me time trying to set up different messages from two different forms based on conditional logic within each form. You gave me an elegant solution that escaped me. Thank you!
Sarah Moyer King says
That’s great, Jared! Thanks for the feedback, glad it helped you, too!
Mark-Jan says
That is really a very great article, thanks! I managed to do step 1 and 2. My url looks like this and I think it’s right:
https://enneagramin-zicht.nl/type-9-de-bemiddelaar-uitgebreid-2/?type1=2&type2=0&type3=0&type4=1&type5=1&type6=personality_quiz_result%5BType6%5D}&type7=2&type8=0&type9=3
Now I am stuck with step 3.
I am not sure how to change the example code to specific code for my website.
Can you help me out and tell me a little more so I can figure it out?
Thanks!
Mark-Jan.
Sarah Moyer King says
Hi Mark-Jan,
I think something like this:
1. Add this to the end of your url:
¶meter=quiz_result_display
2. Add this to your page (this is my step 4):
[form_success_message message='parameter']
3. Add this to your theme’s functions.php file (this is my step 3):
//* Shortcode to display form success on another page
add_shortcode('form_success_message', 'form_message_function');
function form_message_function( $atts ) {
extract( shortcode_atts( array( 'message' => '', ), $atts ) );
// Get var from parameter in Gravity Forms confirmation page url
$success_message = $_GET[$message];
// you can test with: return $_GET[$message];
if( $success_message == 'quiz_result_display' ) {
return 'Success! Here are your quiz results: ....'; }
}
Dozza says
Don’t forget you can also chain-link gravity forms – maybe you could use this to make the decision for them about which second form to complete? See https://docs.gravityforms.com/how-to-chain-forms-using-shortcodes/