Attention !

Cet article contient du code PHP et est destiné aux développeurs. Nous fournissons ce code à titre de courtoisie, mais nous n'offrons pas de support pour les personnalisations de code ou le développement tiers.

Pour obtenir de l'aide supplémentaire, veuillez consulter le tutoriel de WPBeginner sur l'ajout de code personnalisé.

Ignorer

Description

The wpforms_process_validate_email action fires validation on the Email Address form field when the form is submitted.

Paramètres

$field_id
(int) Field ID.
$field_submit
(array) Original raw/unsanitized field value submitted for the field.
$form_data
(array) Paramètres/données du formulaire traités, préparés pour une utilisation ultérieure.

Source

wpforms/includes/class-process.php

Plus d'informations

The wpforms_process_validate_email action is applied to an array for Email Address form field. This function can be used for all form fields do_action( wpforms_process_validate_{$field_type}, $field_id, $field_submit, $form_data ).

For example, to use this for an Single Line Text field, you would use do_action( wpforms_process_validate_text, $field_id, $field_submit, $form_data ).

It’s important to note that field values are not sanitized until later on in the processing, at wpforms_process_format_{$field_type}.

Exemples

You can use this action to scan the Email Address for a specific email address we’ve previously flagged as spam so that it can be blocked.

/*
 * Check the email address field for blocked emails.
 *
 * @link https://wpforms.com/developers/wpforms_process_validate_email/
 *
 * @param int     $field_id        Field ID.
 * @param array   $field_submit    Unsanitized field value submitted for the field.
 * @param array   $form_data       Form data and settings.
*/

function wpf_dev_block_email_address( $field_id, $field_submit, $form_data ) {

    //Create your list of blocked email addresses separated by commas
    $blocked_emails = array( 
        '[email protected]', 
        '[email protected]'
    );
 
    foreach( $blocked_emails as $email ) {
        if(strpos($field_submit, $email) !== FALSE ) {
            wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'Your email address has been flagged as spam. Please contact the site administrator directly if you have further questions.', 'wpforms' );
            return;
        }
    }
}
 
add_action( 'wpforms_process_validate_email', 'wpf_dev_block_email_address', 10, 3 );

Article Reference: How to Create a Global Denylist