Problem: I would like to include two different submit buttons in a Form, and redirect the User conditionally based on which button they clicked.
Solution: You can use multiple submit buttons and test if either is set in the $_POST superglobal. Here's the code from a Form:
[cred_field field="form_submit" output="bootstrap" value="Submit 1" class="btn btn-primary btn-lg"] [cred_field field="form_submit" output="bootstrap" value="Submit 2" class="btn btn-primary btn-lg"]
Then in functions.php:
add_filter('cred_success_redirect', 'custom_redirect_form_abc',10,3); function custom_redirect_form_abc($url, $post_id, $form_data) { if ($form_data['id']==12345){ if (isset($_POST['form_submit_2'])) { $url = "https://yoursite.com/alternate-redirect/"; } } return $url; }
Note that the "form_submit_2" key may need to be modified in your site. Log or dump the $_POST superglobal to find the appropriate key when you submit using the second submit button. You must also set the Form to redirect to some existing post or page in wp-admin, or the redirect override code will not work.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 5 years, 11 months ago.
Assisted by: Christian Cox.