Gravity Forms自定义确认页传参:如何追加特定字符串至查询串
Hey there! Let's figure out how to append that specific string |:||:||:||:|2372 to your Gravity Forms confirmation query string. I've got two solid methods for you to try, depending on your preference:
This approach uses Gravity Forms' gform_confirmation filter to directly adjust the redirect URL after it's built with your existing query string. It's great if you want full control over the final URL.
Add this code to your theme's functions.php file, or use a code snippets plugin (recommended to avoid breaking your theme if you update it):
add_filter( 'gform_confirmation', 'append_custom_string_to_redirect', 10, 4 ); function append_custom_string_to_redirect( $confirmation, $form, $entry, $ajax ) { // Replace YOUR_FORM_ID with the ID of your specific form (find this in the form editor header) if ( $form['id'] !== YOUR_FORM_ID ) { return $confirmation; } // Check if the confirmation is set to redirect to a page if ( isset( $confirmation['redirect'] ) && $confirmation['redirect'] ) { // Append your custom string to the end of the redirect URL $confirmation['redirect'] .= '|:||:||:||:|2372'; } return $confirmation; }
- Just swap out
YOUR_FORM_IDwith the actual ID of your form (you'll see it at the top of the form builder, like "Form ID: 5"). - This code will automatically add your string to the end of the URL that already includes your
gym_name={Gym...}query parameters from the confirmation settings.
If you want to focus only on modifying the query string part (instead of the full URL), use the gform_confirmation_query_string filter. This is perfect since you already have the base query string set up in the form's confirmation settings.
Here's the code:
add_filter( 'gform_confirmation_query_string', 'append_custom_string_to_query', 10, 3 ); function append_custom_string_to_query( $query_string, $form, $entry ) { // Target your specific form if ( $form['id'] !== YOUR_FORM_ID ) { return $query_string; } // Append your custom string to the existing query string $query_string .= '|:||:||:||:|2372'; return $query_string; }
- This will take the query string you already configured (
gym_name={Gym...}) and tack your custom string right onto the end of it, no extra steps needed.
Quick Notes:
- Always back up your site before adding custom code—better safe than sorry!
- After adding the code, submit a test entry to your form and check the URL of the confirmation page to make sure the string is correctly appended.
- If you're not comfortable editing code manually, a plugin like Code Snippets lets you add and manage custom code snippets safely.
内容的提问来源于stack exchange,提问作者ConorBaumgart

