0

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!

1

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:

  1. Check if I already have the data in $form_state.
  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.