You are herehook_form_alter is not called if form fails validation

hook_form_alter is not called if form fails validation


By Marko Blažeković - Posted on 30 December 2015

There is interesting discusion about this here
https://www.drupal.org/node/671574#comment-6466782

and basically how form is cached once something is entered in it, so if validation fails, form will ignore hook_form_alters in that case and loose changes you made. There is a good comment about that here https://www.drupal.org/node/671574#comment-9441525

"It's even incorrect to state that forms are only built once by design, because they aren't. They're only built once if caching is enabled.
..."

Solutions are to use #attached, #after_build and perhaps #pre_render.