I'm working on a module that allows a user to upload an Excel file, and contingent upon what's in the file, send preformatted e-mails to those found within the file. I've used HOOK_file_insert() to do things against the uploaded file without submitting the entire form. What I would like to do is do stuff against the file if and only if certain radio buttons are selected from another field. How can I do this using HOOK_file_insert()?

Long story short, the Excel file contains user account information and this whole module is used to send preformatted messages to the users found within the file. The radio button corresponds to what kind of e-mail to send and when I upload the file and use the HOOK I'm using, I can generate a kind of "preview" of what will be seen in the e-mail. I'd like to use this but use the radio buttons as a means to adjust which e-mail is previewed whereby the actual submission of the form itself sends the actual messages.

Any ideas about this would be appreciated.

Comments

bander2’s picture

You should move this to Module Development and Code Questions.

- Brendan

Jaypan’s picture

You wouldn't do this in hook_file_insert(), as the file is inserted into the files as a temporary file when the file is uploaded, but before your form has been submitted, and as such you won't have access to other form elements when the file is inserted.

You need to do this in your submit handler for the form you are creating. You should have access to the FID in there, from having uploaded the file. You can load the file data using file_load(). Then you would parse the file, and do what you need.

Wolf_22’s picture

That's basically what I wound up doing, Jaypan. Thanks for the insights.