Hi all,

I need to create a module to create a small demo page for a number of program I wrote.
For each node of my new content type I need to upload one main file (the cgi) and a number
of support file (source files).

Now, writing the module is not difficult. It's just the example module + something to upload
a non specified number of file.

Since I love the way the upload module handles attachments, I'm wondering if there is an easy
way to reuse it to attach these files to my content type.
There are problem I need to solve:

- I want the attachment form in the middle of the page (not at the bottom)

- I actually want two attachment forms: One that is required for one file, and another
that is not required, but that can accept a number of files.

I've the feeling I can do all this with alter_form , but I've no idea how to do it. Since the upload module
uses alter_form and doesn't offer a separate form function I'm don't even know if this is possible.

The submit form for my content type should be something like :

+-------------------------------------------
|
| Name :
| Description :
|
| demo program (required) : Attach
|
| source files: Attach
|
|-----------
| Submit|
+--------------------------------------------

where demo program and source files are just standard upload.module forms.

Can anybody tell me if this is possible and how ?

Comments

nevets’s picture

You will not directly be able to use the upload code "as is" the way you want since two instances would have the same form fields and I suspect the files uploads would clash.

A couple of approaches, you could use the upload module to get the list of source files plus a little vodoo to place it where you want (see below) then use a generic file field for the required file and handle that one in you module.

Another approach might be to use the content (aka CCK) module to add fields to your content type. In particular the File Field. That would allow more the one, have one required/one not, determine the ordering of the fields and hopeful allow for multiple files in the one case (I have not tried the file field yet). I would invistigte this approach myself.

upload vodoo: Modules hooks by default run un alphabitical order, so the upload module would normally run after your demo module. But there is a fiield in the system table called weight and like all things drupal, module with a larger weight run later (modules with the same weight run in alphabitical order). So it you set your module weight to something greater than zero, then your module hooks will run after the upload modules hook, In particular, your form_alter hook will run after the upload_form_alter so you would be able to see the changes made by it and change the weight(s).