Elementor submits its form via ajax, so you can’t just do a $_POST grab on a page submit. You need to use its hooks.
Form submit complete (with optional redirect)
//**********************************************
//**********************************************
//********** ELEMENTOR FORM SUBMITTED **********
//**********************************************
//**********************************************
add_action( 'elementor_pro/forms/new_record', function( $record, $handler )
{
$form_name = $record->get_form_settings( 'form_name' ); //<<<Set in form widget > Content > Form fields > Form name
if ($form_name == 'my_form_name')
{
//----- HANDLE my_form_name FORM SUBMISSION -----
//CREATE AN ARRAY OF ALL THE SUBMITED FORM FIELDS
$RawFields = $record->get( 'fields' );
$FormFields = [];
foreach ( $RawFields as $Id => $Field )
$FormFields[ $Id ] = $Field['value'];
$Email = $FormFields['Email'] ?? ''; //<<<Set in form widget > Content > Form fields > Select the field > Advanced > ID
//CHECK ENTERED VALUES
if (email_exists($Email))
{
$handler->add_error(
'Email', //<<<The ID of the field to show the error message under
'An account with this email address already exists.' //<<<The error message to show
);
$handler->is_success = false;
return;
}
//FORM ACCEPTED
//Cause a re-direct
//(This will work on a form with nothing set in 'Actions after submit')
$redirect_url = '/my_page2';
$redirect_to = $record->replace_setting_shortcodes( $redirect_url );
$handler->add_response_data( 'redirect_url', $redirect_to ); //Set redirect action to handler
}
}, 10, 2);
