How to set default form values based on query string, if the form uses AJAX file upload I have a Book content type with a file upload field.
I'm using Filefield Sources module with Plupload integration for getting the file upload widget.

I need to set a default value based on the query string passed on node/add/book page.

However, the files are uploaded via AJAX, calling the file/ajax page, and losing all default values I set. Obviously, custom query string is not present in that call, and when the form is re-generated, I get an error.

Any ideas on how can I make sure that default values stay in the form?

Thanks!
I forgot to post the answer.

To keep the data persistent between AJAX calls, you should store it in the $form_state variable. This is how it worked in my case:


Check if I already have the data in $form_state.
If not and if there is query string, get the data, sanitize/validate it and store in $form_state.


This way it works even for AJAX calls where query string parameters are not available.