I have a managed_file #upload_validators callback and when it is called the $form_state does not get passed along with it. My goal is to use another field in the form to rename the uploaded file. I just need access to that during the validation. Maybe I shouldn't be using a validator callback for renaming the file and displaying in the UI immediately but this but it is all I can think of at the moment.


It appears we can use this code to get the $form_state, however, there are no $form_state['values'].

$form_state = form_state_defaults(); // $form_state is passed by reference and will be updated automatically. form_get_cache($_REQUEST['form_build_id'], $form_state);

I was able to find the value in $form_state['field']['field_NAME']['und']['entity'][0]->field_NAME['und'][0];

However, this will not pass along the value you set in another field without first setting an #ajax callback on that field, the callback can just return NULL, it is just to update the form.

In our case we disable the file upload field until the other field has first been set.

Hopefully this will help someone or most likely myself in a year from now.

sources: https://twitter.com/eojthebrave/status/743544054030336000 && How do I load the $form_state for a form loaded with drupal_get_form?

| improve this answer | |

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.