I have a multi-step form using AJAX. When you submit the form it increments the step, and then sets
TRUE, and the entire form is replaced by AJAX.
It works fine, right up until one of the steps involved calling
user_login_finalize() in the submit handler - the user can go from anonymous to logged in. Then when it tries to build the next step I get the error:
Form errors cannot be set after form validation has finished
I puzzled over this error for a while. I thought the validation handler might be firing twice, but then I saw in the debug trace that
setInvalidTokenError() is being called in
After looking in
doBuildForm(), I think the problem is that Drupal thinks the form is being submitted in a naughty way or has the wrong token. What can I do?