| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | use Forge12\DoubleOptIn\EmailTemplates\PlaceholderMapper; |
| 13 | 13 | use Forge12\DoubleOptIn\FollowUp\FollowUpAttempt; |
| 14 | 14 | use Forge12\DoubleOptIn\FollowUp\FollowUpCoordinator; |
| 15 | 15 | use Forge12\DoubleOptIn\FollowUp\FollowUpResult; |
| 16 | +use Forge12\DoubleOptIn\Frontend\ErrorNotification; | |
| 16 | 17 | use forge12\contactform7\CF7DoubleOptIn\Category; |
| 17 | 18 | use forge12\contactform7\CF7DoubleOptIn\CF7DoubleOptIn; |
| 18 | 19 | use forge12\contactform7\CF7DoubleOptIn\HTMLSelect; |
| 19 | 20 | use forge12\contactform7\CF7DoubleOptIn\OptIn; |
| @@ -286,14 +287,19 @@ | ||
| 286 | 287 | // Always prevent the original CF7 mail from being sent when opt-in creation fails |
| 287 | 288 | add_filter( 'wpcf7_skip_mail', '__return_true' ); |
| 288 | 289 | |
| 289 | 290 | $error = self::getLastError(); |
| 290 | - if ( $error && apply_filters( 'f12_cf7_doubleoptin_show_validation_error', false ) ) { | |
| 291 | + // Abort with the reason instead of CF7's "sent": CF7 then keeps the | |
| 292 | + // visitor's input and shows the message in the form. A refused | |
| 293 | + // consent always takes this path (OptInError::isAlwaysShown()). | |
| 294 | + if ( $error && $error->shouldShowToVisitor( (int) $formId ) ) { | |
| 291 | 295 | $message = apply_filters( 'f12_cf7_doubleoptin_error_message', $error->getMessage(), $error, $formId ); |
| 292 | 296 | if ( method_exists( $submission, 'set_response' ) ) { |
| 293 | 297 | $submission->set_response( $message ); |
| 294 | 298 | } |
| 295 | 299 | $abort = true; |
| 300 | + // The form shows it now — no second copy in the toast. | |
| 301 | + ErrorNotification::forget(); | |
| 296 | 302 | } |
| 297 | 303 | return; |
| 298 | 304 | } |
| 299 | 305 | |