-
Notifications
You must be signed in to change notification settings - Fork 43
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
Invalid CSRF token + missing errors #67
Comments
OK, so after some tinkering I found that the missing errors are because the changeset doesn't have an action key set. The issue with csrf remains a problem, however. Are there workarounds I can use? |
This is because you are poking There is no easy workaround, I am afraid. For the fix, Drab could save all tokens on the client side at load, and re-set it on each poke. Any other ideas? |
The only other way I can think of is to update the form fields individually, I suppose, but that might not be too far removed from a JS/Ajax solution. |
Well, in theory I could parse the AST for Or create Drab version of |
Yeah, I'm not sure it's worth it, but it would be nice to have drab work with forms in that way. I'm not sure |
I will just first try to save the csfr before updating, as it is the simplest solution. Thanks for all the feedback! |
Well, I just thought of something. I can split the form into two: One for Drab and one for the record. The Drab form would submit and update the changeset of the record form. Since the record form has not been submitted, it should work fine. Or is that, simply by Drab updating the changeset, the CSRF error will happen? |
If you use the "normal html", not submitting button, and just give it a |
Right. My intention though is to use Drab to preload the form, and then submit the form via normal HTML. In that case I would split the form into two pieces. The drab one continues to work on the on keyup handle, uses the commanded to fetch data and prepopulate the changeset for the second form. But what you are saying is that if Drab updates the second changeset, submitting the form over normal html would result in the same error? |
You can always use |
Hi @abitdodgy , # safe the existing token
{:ok, %{"value" => token}} = query_one socket, "form > input[name='_csrf_token']", :value
# re-render the form
poke socket, "#form_holder", innerHTML: Phoenix.View.render(MyView, "form.html", assign: "value")
# set the token back
set_attr socket, "form > input[name='_csrf_token']", value: token I am going to put this on Drab's wiki. Thanks! |
I'm using drab to fetch a URL and prepopulate a form. However, when I submit the form (vanilla, not using drab for the submission), I get an invalid csrf token. I'm assuming it's because the prefetch request that I did through drab used up the csrf token? What would be the best way to go about refreshing it?
Here's what I'm doing:
In my commander:
Another issue I'm running into is not being able to show changeset errors. For example, the
else
branch above returns an invalid changeset with errors which the form should render, but the form doesn't render out the errors.The text was updated successfully, but these errors were encountered: