Riassunto AI
Descrizione
Filtra il messaggio di conferma dell'output a livello di sito.
Parametri
- $message
- (string) (Richiesto) Messaggio di conferma, inclusi Smart Tag elaborati.
- $form_data
- (array) (Richiesto) Impostazioni/dati del modulo elaborati, preparati per essere utilizzati in seguito.
- $fields
- (array) (Richiesto) Dati dei campi sanificati.
- $entry_id
- (int) (Richiesto) ID della voce.
Origine
wpforms/src/Frontend/Frontend.php
Maggiori Informazioni
Il filtro viene applicato a tutti i moduli impostati per visualizzare un messaggio di conferma. Può essere utilizzato per modificare o sostituire il messaggio di conferma visualizzato, sovrascrivendo il contenuto del messaggio impostato all'interno del modulo.
Esempi
L'esempio mostrato di seguito catturerà il nome utente che ha compilato il modulo e quindi fornirà un messaggio più personalizzato per il messaggio di conferma.
Ricorda solo di cambiare l'ID del modulo da 25 per farlo corrispondere all'ID specifico del modulo su cui desideri eseguire il tuo codice. La rimozione di questo controllo lo eseguirebbe per tutti i moduli.
/**
* 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 );