Last active
June 12, 2024 13:50
-
-
Save w3b-beweb/c88c77b07fdd1c09150385dabbd927aa to your computer and use it in GitHub Desktop.
Elementor pro forms Generate an error on ajax submit of the form and stop processing actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'elementor_pro/forms/validation', function( $record, $ajax_handler ) { | |
//make sure its our form | |
$form_name = $record->get_form_settings( 'form_name' ); | |
if ( 'Name of the form' !== $form_name ) { | |
return; | |
} | |
$field = $record->get_field( ['id' => 'email'] ); | |
$email_array = $field['email']; | |
if ( $some_condition ){ | |
//field error on message | |
$msg = "Something has occurred"; | |
//highlight the field causing the error | |
$ajax_handler->add_error( $email_array['id'], $msg ); | |
//show a error message for the form | |
$ajax_handler->add_error_message( "Please verify highlighted fields" ); | |
} | |
}, 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment