Résumé IA
Description
Le filtre wpforms_process_redirect_url s'active lors de la soumission du formulaire pour charger l'URL nécessaire à la redirection.
Paramètres
- $url
- (string) URL pour la redirection.
- $id_formulaire
- (int) ID du formulaire.
- $form_data
- (tableau) Paramètres/données du formulaire traités, préparés pour une utilisation ultérieure.
- $fields
- (tableau) Données du champ nettoyées.
- $entry_id
- (int) ID de l'entrée.
Source
wpforms/includes/class-process.php
Plus d'informations
Le filtre wpforms_process_redirect_url qui sera utilisé pour la redirection une fois le formulaire soumis.
Exemples
Dans cet exemple, nous allons configurer le formulaire pour une redirection dans les paramètres du constructeur de formulaire, puis, en fonction d'une question spécifique du formulaire, rediriger l'utilisateur vers différentes URL en fonction de la réponse.
Si vous prévoyez d'utiliser cet extrait, il est important de se rappeler que dans l'onglet Paramètres, sous la section Confirmations, veuillez définir le Type de confirmation sur Aller à l'URL (Redirection). Pour plus d'informations à ce sujet, veuillez consulter cette documentation.
/** * 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.