Skip Navigation

[Gelöst] Second submit form button with custom redirect to page

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 support ticket is created vor 5 Jahren, 11 Monaten. There's a good chance that you are reading advice that it now obsolete.

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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von SteffenM1628 vor 5 Jahren, 11 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1162380

Tell us what you are trying to do?
Hey there,
i would like to have a second submit button in i form with a custom redirect to another page than the first submit button.
Why?:
the user should choose when he saves the form to use submit button 1 to get to the post which he has created, or use submit button 2 to save the form but go back to his e.g. user dashboard where all his post are listed in a view.

This is what i found in other threads:
Is the working with the cred api and also for buttons with an id?

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return '<em><u>hidden link</u></em>';
    return $url;
}

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

or is there another way to get the user to two different sites after submitting the form?

Thanks for your help.
Cheers

#1162493

Hi, 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 = "<em><u>versteckter Link</u></em>";
    }
  }
  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.

#1162983

Thank you soooo much worked out of the box!!!!!