View Single Post
Old 09-19-2007, 07:50 PM   #1 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,182
Thanks: 88
Wildhoney is on a distinguished road
Angry Form Enctype in Internet Explorer

I'm sure every single programmer knows that Internet Explorer has its funny little ways. Getting used to all the funny little ways is somewhat of a mammoth task - and speaking of mammoths, would take the mind the size of a mammoth to memorise them all. Here's another one to put in your collection!

javascript Code:
pForm = document.createElement('form');
pForm.setAttribute('method', 'post');
pForm.setAttribute('action', 'index.php');
pForm.setAttribute('enctype', 'multipart/form-data');

The above code looks so simple. We create a form ready to include into our page. Now, when I was coding Pture.com I did just that. However, as soon as I tested it in Internet Explorer for my file uploads, the uploads wouldn't work. After some investigation I realised Internet Explorer wasn't setting the enctype attribute on my dynamically created form. After some subsequent research I found out that when creating forms dynamically in Internet Explorer (both 6 and 7) using Javascript, you need to also set the encoding attribute, for some reason. So although the attribute is called enctype, setting the enctype does nothing. The following code will work:

javascript Code:
pForm = document.createElement('form');
pForm.setAttribute('method', 'post');
pForm.setAttribute('action', 'index.php');
pForm.setAttribute('enctype', 'multipart/form-data');
pForm.setAttribute('encoding', 'multipart/form-data');

Which will save you a good few hours!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.

Last edited by Wildhoney : 01-09-2008 at 03:33 AM.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote