Append extra data in FormData #7581
Answered
by
teemingc
NormandoHall
asked this question in
Q&A
-
I have a form and I want to add reCaptcha <form
class="space-y-6"
action="?/login"
method="POST"
use:enhance={({ data }) => {
console.log('1');
grecaptcha.ready(function () {
grecaptcha.execute(PUBLIC_RECAPTCHA_SITE_KEY, { action: 'submit' }).then(function (t) {
console.log('2');
data.append('token', t);
});
});
console.log('3');
return async ({ result }) => {
await invalidateAll();
await applyAction(result);
};
}}
>
<input..../>
<input.../>
<button type="submit">Submit>/button>
</form> I get console log 1, 3, 2. Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
teemingc
Nov 10, 2022
Replies: 1 comment 11 replies
-
Does this work? <form
class="space-y-6"
action="?/login"
method="POST"
- use:enhance={({ data }) => {
+ use:enhance={ async ({data}) => {
console.log('1');
+ const captcha = new Promise((resolve) => {
grecaptcha.ready(function () {
grecaptcha.execute(PUBLIC_RECAPTCHA_SITE_KEY, { action: 'submit' }).then(function (t) {
console.log('2');
data.append('token', t);
+ resolve();
});
});
+ });
+ await captcha;
console.log('3');
return async ({ result }) => {
await invalidateAll();
await applyAction(result);
};
}}
>
<input..../>
<input.../>
<button type="submit">Submit>/button>
</form> |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
NormandoHall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work?