1

I need conceptual clarification. I have fields of a form that I want to populate by letting a user use an XML file so my custom form module can parse and assign XML to form fields. I do not need to keep the XML file permanently.

First question: When using the file field widget on my form, after I select my file and the file name appears on the form, Drupal or the browser seem to have it stored in memory somewhere. It is possible to parse the XML file from this location in memory with a submit handler that populates the form? (So 2 submit handlers on the form, one to submit the XML to populate form and the other to submit the form to create node.)

Last question: Would this be easier if I have a form with a single file widget that uploads an XML file to a temp directory and builds + renders a form on the node after it has parsed the data?

Thanks all!

1

I suggest you use the Feeds module. (I believe you may need to also read up on its SimplePie integration to help with the XML.)

Basically, it provides you with the form and functionality for importing, storing, and reading your XML file. It is also designed to create a node using the info read from the XML file.

If you don't want a new node, then you can interrupt the process using hook_feeds_presave to work with the info that Feeds has read from the uploaded file. (For example, to load and populate a form with the imported info. I'm looking into doing just that, myself.)

If you didn't want to use Feeds, then read up on the File interface and File API, which let you work with the uploaded file, store it temporarily, read data from it, etc. I've found that very useful.

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.