Showing a message while downloading a file from hook_form_submit I have a form which creates a csv file and starts a download if it is successful. I also attempt to show a success message at this point but it never shows up because I use drupal_goto to download the file and since it is a file download the page does not refresh:

drupal_set_message("Student accounts created. Please keep the roster CSV filed that has just been download for your future use.");

drupal_goto( file_create_url($file-&gt;uri));


Another problem here is that any warning messages from previous failed validation (in hook_form_validate) remain on the page even after success. How Can I the page to refresh while starting a download from hook_form_submit?
Your workflow lacks one step. What you want it to be, is:


Send user to "Your download should start shortly" page. On that page, place a script that will execute file download in new window after some arguably small timeout, and a target="_blank" link to the file, for cases when auto-downloading is disabled client side for security reasons.
When the script executes successfully and starts to download file for user, or when user clicks the link to direct download, use JS to send him to "thank you" page. Of course if JS fails, it might not get executed, so be sure all courtesy you really need is also displayed on the page mentioned in point one.