multipart/form-data problem

A

Alex Sibilev

Hello,

I have a really weird problem I've been trying to solve it without any luck
for the last couple of hours :(
I'm writing a "conference board" application (quite similar to ASP.NET
forum).
I don't use server controls in it (apart from Page).

The problem occurs on the page where visitor can post a new messages.
Basically, it's a form with couple of
edit controls, hidden fields, buttons and and a file upload control. Form
enctype is multipart/form-data (to enable file uploads)
The first 5 fields after <FORM> is hidden fields (Thats important!) When
user post that form I use Request.Params to extract required data.

The problem appeared after I added two checkbox controls at the end of the
form.

Now, if user types-in anything using multibyte encoding (i.e. in jewish,
arabic, ... or just special characters) and posts the form the 1st hidden
field
will go missing when I try to access it via Request.Params. Only 1st one -
all other fields will be just fine.

If I remove enctype="multipart/form-data" it will work fine. If I remove
last checkboxes it will work fine.
If I'll just use English it will work fine.

I understand it's very lengthy explanation and probably a bit confusing, but
I really stuck on this one.

I would appreciate any help and will be happy provide addiitonal information
if required.

Thanks in advance.

Alex
 
K

Karl

Is there a reason you are using Request.Param instead of the asp.net method
of using web or html controls? You should try it and see if it'll fix your
problem.

Karl
 
A

Alex Sibilev

Thanks for reply Karl,

I have my own html template processor and trying to squeeze from ASP.NET
everything I can, performance wise.
So I turned off Viewstate, AutoEventWireUp and using basic Request.Params &
Forms to get posted data.

Also I noticed more weird behaviour today. In my HTML I've got fields in
this order:
<form>
hidden fields
entry fields (text, textarea, radio)
submit buttons
checkboxes
</form>

Now, if I swap submit buttons with checkboxes it all starts to work. It
really driving me nuts.

Alex
 
U

Unit

I suppose in the meanwhile you solved the problem already, but since
I've been experiencing the same problem I'm going to post something
here anyway ;) (it may be useful still). The trouble here is this:

When you change the enctype to "multipart/form-data", you change the
way the form is sent, and apparantly it doesn't support the
checkboxes. The "multipart/form-data"-enctype neglects everything in
the code that is written under the submit-button. From there the
enctype automaticly changes back to the defauld
"application/x-www-form-urlencoded", so thats why the checkboxes will
work properly when situated under the submit.

Since locating the checkboxes únder the submit-button looks stupid, I
didn't accept this as a solution. This is the way I díd solve it:
I created a form inside a form. I didn't really expect it to work, but
it accually did :D. This is how it works:
Instead of this:

<form enctype="multipart/form-data" action="asppage.asp"
method="post">

<input type="file" name="file">
<input type="checkbox" name="checkbox">

<input type="submit">
</form>

I wrote this:

<form enctype="multipart/form-data" action="asppage.asp"
method="post">

<input type="file" name="file">
<form>
<input type="checkbox" name="checkbox">

<input type="submit">
</form>
</form>

This worked for me. All data was send and I was able to use it the way
wanted it to. I'm not sure it will work for everyone else having this
problem, but else you could always try to use dropdowns-menues with
yes/no inside them. I suppose that'll work also but it'll look less
good :p.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
K

Kevin Spencer

Hi Unit,

You have some basic misunderstandings here. I hope I can clear them up for
you.
When you change the enctype to "multipart/form-data", you change the
way the form is sent, and apparantly it doesn't support the
checkboxes. The "multipart/form-data"-enctype neglects everything in
the code that is written under the submit-button. From there the
enctype automaticly changes back to the defauld
"application/x-www-form-urlencoded", so thats why the checkboxes will
work properly when situated under the submit.

This is all incorrect. Remember that we're talking about an HTML document
here, as far as the form is concerned. An HTML form can have only ONE
encoding type. That is defined in the form tag. If the enctype attribute is
set to "multipart/form-data," the entire form is encoded in that way. It has
nothing to do with any submit button, or checkboxes, or anything else except
the "enctype" tag. Everything in the form is encoded in the same way. Note
that I said "everything in the form." You can have more than one form on a
page. When a form submits, it doesn't submit the page, but only the form
fields contained within that form. So, you might want to check whether or
not you have more than one form on the page, or if some of the form fields
are outside of the form.

Checkbox data is indeed sent with the rest of the form data. I don't know
why you can't seem to get the data from the CheckBox, as you didn't describe
the issue you're having.
Since locating the checkboxes únder the submit-button looks stupid, I
didn't accept this as a solution. This is the way I díd solve it:
I created a form inside a form. I didn't really expect it to work, but
it accually did :D. This is how it works:

Your solution may have worked on the browser you tested it on, but it is not
right. You cannot nest forms in HTML. Well, as you have discovered, you CAN,
but it is a violation of the W3C standard to do so, and may produce
unexpected results depending upon the browser. In any case, it's a hack. And
it will bite you at some point.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top