Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax-Form | Second attempt fails #89

Closed
jensfranke opened this issue Apr 20, 2016 · 2 comments
Closed

Ajax-Form | Second attempt fails #89

jensfranke opened this issue Apr 20, 2016 · 2 comments

Comments

@jensfranke
Copy link

My setup is similar to https://forum.getkirby.com/t/how-to-create-a-newsletter-subscription-form-using-uniform-mailchimp/3677/12

The first attempt runs without any problems, but if the email is for example already in the list the user needs to send a second form (with a new email address). The response then is always false, maybe this is an issue with a new generated token?

Thanks in advance for you help
Jens

@mzur
Copy link
Owner

mzur commented Apr 20, 2016

The response then is always false, maybe this is an issue with a new generated token?

It most probably is. The token is reset whenever the form was submitted successfully. In your example an email that already exists is a success:

// Email already in the list
if ($response['status'] == 400) {
    $result['success'] = true;

You can get the new token after the first form submission was processed and return it with the success/error message so the next form submission can use the new token. Your JSON response of the route might look like this:

return response::json([
   'success' => $form->successful(),
   'message' => $form->message(),
   'errors' => $errors,
   'token' => $form->token(),
]);

@jensfranke
Copy link
Author

Ah, works perfect! Thanks for your work & help – really great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants