Beschreibung

Filtert die Ausgabe von Bestätigungsmeldungen für die gesamte Website.

Parameter

$Nachricht
(string) (Erforderlich) Bestätigungsnachricht, einschließlich verarbeiteter Smart Tags.
$form_data
(array) (Erforderlich) Verarbeitete Formulareinstellungen/Daten, die für die spätere Verwendung vorbereitet sind.
$Felder
(array) (Erforderlich) Bereinigte Felddaten.
$Eintrag_id
(int) (Erforderlich) Eintragsnummer.

Quelle

wpforms/src/Frontend/Frontend.php

Mehr Informationen

Der Filter wird auf alle Formulare angewendet, die eine Bestätigungsmeldung anzeigen sollen. Er kann verwendet werden, um die angezeigte Bestätigungsnachricht zu ändern oder zu ersetzen und den im Formularersteller eingestellten Nachrichteninhalt außer Kraft zu setzen.

Beispiele

Das unten gezeigte Beispiel erfasst den Namen des Benutzers, der das Formular ausgefüllt hat, und gibt dann eine persönlichere Nachricht für die Bestätigungsmeldung aus.

Denken Sie nur daran, die Formular-ID von 25 mit der spezifischen Formular-ID übereinstimmen, für die Sie Ihren Code ausführen möchten. Wenn Sie diese Prüfung entfernen, wird der Code für alle Formulare ausgeführt.

/**
 * Filters confirmation message output site-wide.
 *
 * @link   https://wpforms.com/developers/wpforms_frontend_confirmation_message/
 * 
 * @param  string   $message     Confirmation message including Smart Tags.
 * @param  array    $form_data   Form data and settings.
 * @param  array    $fields      Sanitized field data.
 * @param  int      $entry_id    Entry ID.
 *
 * @return string
 */

function wpf_dev_frontend_confirmation_message( $message, $form_data, $fields, $entry_id ) {
    
    // Only run on my form with ID = 25
    if ( absint( $form_data[ 'id' ] ) !== 25 ) {
            return $message;
        } 

    // also it is possible to access the first, middle, and the last name as follows inplace of [ 'value' ]
    //  $contact_name = $fields[ '0' ][ 'first' ]; - this will pass in the first name
    //  $contact_name = $fields[ '0' ][ 'last' ]; - this will pass in the last name
    //  $contact_name = $fields[ '0' ][ 'middle' ]; - this will pass in the middle name in the format First Middle Last
         
    // Get the name field ID '0' to set the name for the message
    $contact_name = $fields[ '0' ][ 'value' ];
    
    // Add the name to the message
    $message = __('Thanks ' . $contact_name .  ' we will be in touch!', 'plugin-domain');
    return $message;
     
}
add_filter( 'wpforms_frontend_confirmation_message', 'wpf_dev_frontend_confirmation_message', 10, 4 );

Referenzartikel