Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save w3b-beweb/c88c77b07fdd1c09150385dabbd927aa to your computer and use it in GitHub Desktop.
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
<?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