Preview Not Updating After $form_state['rebuild]
| Project: | Upload element |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | won't fix |
Jump to:
Hi I've been banging my head against the wall over this issue for a couple days now and I'm not sure what's going on. I have a multi-page form with an image_upload_element on one the pages defined by:
$form['veterinarians']['photo'] = array(
'#type' => 'image_upload_element',
'#title' => t('Veterinarian picture'),
'#required' => $required,
'#default_value' => $form->image,
'#image_preview_size' => '200x200',
);
When the user submits this part of the form, it goes to a function that validates and uploads the image entered. After validation
$form_state['rebuild'] = TRUE is called to return the user to that page of the form if they want to add more images. However with version 6.x-1.2 when they browse for the file and click 'Update' the picture from the previous upload displays instead of the new one. What's weird is in the temp directory the correct file is getting stored and when i submit the page the correct file is uploaded - it's just not displayed on the preview. I've also tried the 6.x-1.x-dev and after submitting the first image, when the page is reloaded with $form_state['rebuild'] the original picture immediately pops up in the preview. I'm not sure what's causing this but any help would be greatly appreciated.
Thank you!!

#1
To save setting up a test environment for this use case, can you try with all browser caching turned off? Thanks
#2
Hey Alan,
I disabled caching in my browser, deleted drupal's cache and set it to no caching mode and the problem still occurs. It's like every element gets refreshed except for the preview part of the image upload element. Is there any other information i could give you that would make troubleshooting this easier?
Thank you
#3
Looks like there is some sort of error with the element. This was created as a proof of concept element to use the hook_value to handle file uploads, but there was no way to use this function to store results directly in the form state, and a number of workarounds were required. I'll try and get some time to look at it over the next week or so, maybe this weekend.
Drupal 7 appears to have two important fixes/changes that will make things easier.
#4
Thanks Alan, I'm still trying to get it to work as well so if I stumble across anything I'll let you know
#5
Seems to fit outside of the normal scope and with managed_file in core (very similar element) I'm marking this as closed simply due to the amount of time it looks like it would appear to take to resolve.
PS: Much easier just to save, and not to redirect. New form, clean slate and no issue ;]