Form Attachments Part 2
The CodeThe code is going to look familiar at first, but don't jump to grab it just yet. There are some major changes to the basic form you may be used to dealing with. Here's what created the form above. I'll only offer the main form command and the tag that created the attachment element. The rest is basic form code that you already know:
<FORM METHOD="post" ACTION="mailto:firstname.lastname@example.org" ENCTYPE="multipart/form-data">
Attachment: <INPUT TYPE="file" NAME="attachedfile" MAXLENGTH=50 ALLOW="text/*" >
In order to use the attachment input tag, the form itself must be set to the "post" METHOD. You probably have always done that, but I wanted to point it out anyway.
The ACTION statement is still the basic mailto: format.
Note, finally, the ENCTYPE (encryption type). It is set to the MIME (Multipart Internet Mail Extensions) content-type "multipart/form-data". That's important. That setting allows for numerous file types to be transferred, rather than just the common text/plain. The form must be set to MIME for the attachment input item to have a shot at working. The button will always pop up a dialog box to attach a file. That function will always be available, but without the ENCTYPE MIME setting, the form won't send the attachment.
Now that input tag...
The Input TagThe basic input format is retained. The TYPE setting is "file". That's what produces the Browse button. I'm sorry to say that the button says "Browse" no matter what you do. It does not respond to the VALUE attribute.
The NAME is set so the input element can be associated with the form, and finally you get into a new attribute, ALLOW.
The ALLOW attribute acts to allow you to set the MIME-type for the type of file you intend send. In order to use the command correctly, you need to get hold of a list of all of the MIME-types used on the Web.
Here's a good list I often use.
I have this particular setting to text/*. That star is inclusive. That means the input element will accept any of the text-based input items. I should say that many of the posts I ran into while researching this tutorial stated that this ALLOW attribute was worthless. The tag reacted the same with or without the attribute involved. I used the attribute each time I worked with the system.
That's ThatSorry to end so abruptly, but that's really it. That's all I could get to work. I was successful with text-based documents like HTML. Word files and images never did come through correctly. They seemed to attach and send just fine, but would be destroyed when they arrived in my e-mail box.
Oh well, use it in good health and keep an eye out for CGIs that work with the command. I read a few posts that swear they are out there...although I never saw one. If you find one, let me know.