KI-Zusammenfassung
Beschreibung
Der wpforms_process_redirect_url Filter wird beim Absenden des Formulars ausgelöst, um die für die Weiterleitung benötigte URL zu laden.
Parameter
- $url
- (string) URL für die Weiterleitung.
- $form_id
- (int) Formular-ID.
- $form_data
- (array) Verarbeitete Formulareinstellungen/Daten, die zur späteren Verwendung vorbereitet sind.
- $fields
- (array) Bereinigte Felddaten.
- $entry_id
- (int) Eintrag-ID.
Quelle
wpforms/includes/class-process.php
Weitere Informationen
Der wpforms_process_redirect_url Filter, der für die Weiterleitung verwendet wird, sobald das Formular gesendet wurde.
Beispiele
In diesem Beispiel richten wir das Formular für eine Weiterleitung in den Formular-Builder-Einstellungen ein und leiten den Benutzer dann basierend auf einer bestimmten Frage im Formular basierend auf der Antwort zu verschiedenen URLs weiter.
Wenn Sie planen, diesen Ausschnitt zu verwenden, ist es wichtig zu bedenken, dass Sie unter der Registerkarte Einstellungen im Abschnitt Bestätigungen den Bestätigungstyp auf Zur URL gehen (Weiterleiten) setzen müssen. Weitere Informationen hierzu finden Sie in dieser Dokumentation.
/** * Redirect URL. * * @link https://wpforms.com/developers/wpforms_process_redirect_url/ * * @param string $url URL to redirect to. * @param int $form_id The form ID. * @param array $form_data Processed form settings/data. * @param array $fields Sanitized fields data. * @param int $entry_id Entry id. * * @return string */ function wpf_dev_process_redirect_url( $url, $form_id, $fields, $form_data, $entry_id ) { // Only run on my form with ID = 879. if ( absint( $form_data[ 'id' ] ) !== 879 ) { return $url; } // Assign the checkbox field that shows the room number to a variable $room_number = $fields[4][ 'value' ]; if ($room_number === "Room A") { // Redirect to page with Room A information $url = 'http://myexamplesite.com/room-a-info'; } elseif ($room_number === "Room B") { // Redirect to page with Room B information $url = 'http://myexamplesite.com/room-b-info'; } elseif ($room_number === "Room C") { // Redirect to page with Room C information $url = 'http://myexamplesite.com/room-c-info'; } else { // Keep the current redirect URL that is set in the form builder settings $url = $url; } return $url; } add_filter( 'wpforms_process_redirect_url', 'wpf_dev_process_redirect_url', 10, 5 );Using this snippet means that any URL you have set on the Confirmations tab will be ignored and utilize this redirect instead.
If the user selects to reserve Room A, the form will ignore the URL from the form builder’s redirect settings on the Confirmations tab and instead redirect to a URL containing information about Room A. The loop continues through the options listed for each room with a fallback in the final
elseand keeps the original URL from the form builder settings.