| @@ -82,15 +82,51 @@ | ||
| 82 | 82 | |
| 83 | 83 | // Get the parent form of the submit button. |
| 84 | 84 | const form = submitButton.closest('form'); |
| 85 | 85 | |
| 86 | - // Submit the form. | |
| 87 | - form.submit(); | |
| 86 | + // Submit the form, using requestSubmit() so any submit event listeners are honored | |
| 87 | + // e.g. the Member Content login form, which submits using AJAX. | |
| 88 | + form.requestSubmit(); | |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | 91 | // Scope the function to the window object as webpack will wrap everything in a closure, |
| 91 | 92 | // resulting in the function not being available globally. |
| 92 | 93 | window.convertKitRecaptchaFormSubmit = convertKitRecaptchaFormSubmit; |
| 94 | + | |
| 95 | +/** | |
| 96 | + * Handles form submissions when Cloudflare Turnstile is enabled. | |
| 97 | + * | |
| 98 | + * Turnstile auto-populates a hidden `cf-turnstile-response` input inside the | |
| 99 | + * enclosing form once the challenge is solved, so we just need to submit the | |
| 100 | + * containing form when the callback fires. | |
| 101 | + * | |
| 102 | + * @param {string} token Turnstile response token. | |
| 103 | + */ | |
| 104 | +function convertKitTurnstileFormSubmit(token) { | |
| 105 | + // Find the Turnstile widget div with the data-callback attribute. | |
| 106 | + const widget = document.querySelector( | |
| 107 | + '.cf-turnstile[data-callback="convertKitTurnstileFormSubmit"]' | |
| 108 | + ); | |
| 109 | + | |
| 110 | + if (!widget) { | |
| 111 | + return; | |
| 112 | + } | |
| 113 | + | |
| 114 | + // Get the parent form of the widget. | |
| 115 | + const form = widget.closest('form'); | |
| 116 | + | |
| 117 | + if (!form) { | |
| 118 | + return; | |
| 119 | + } | |
| 120 | + | |
| 121 | + // Submit the form, using requestSubmit() so any submit event listeners are honored | |
| 122 | + // e.g. the Member Content login form, which submits using AJAX. | |
| 123 | + form.requestSubmit(); | |
| 124 | +} | |
| 125 | + | |
| 126 | +// Scope the function to the window object as webpack will wrap everything in a closure, | |
| 127 | +// resulting in the function not being available globally. | |
| 128 | +window.convertKitTurnstileFormSubmit = convertKitTurnstileFormSubmit; | |
| 93 | 129 | /* eslint-enable no-unused-vars */ |
| 94 | 130 | |
| 95 | 131 | /** |
| 96 | 132 | * Register events on frontend. |