HTML form values adding commas in Classic ASP

2019-03-29 01:24发布

问题:

I have a classic ASP page that submits back to itself. Strangely, the values being returned from the selects have commas being added to the ends of them. Has anyone run into anything like this before? Any troubleshooting steps or tools recommended?

I'm expecting the values to be returned just as numbers - they are the IDs of the values displayed in the option.

I've checked for mystery commas in the page and can't locate any - nor in the data that I'm pulling through.

(note - these are single-selects, not multiple)

回答1:

Sounds like you have duplicate form fields. Your values are concatenated together with commas, like this:

<input type="text" name="name1" value="value1">
<input type="text" name="name1" value="value2">
<input type="text" name="name2" value="value3">

Becomes

name1=value1,value2
name2=value3

If the second name1 has no value, it becomes

name1=value1,
name2=value3


回答2:

Do you have multiple form elements on your page with the same name?

In classic ASP, multiple form values with the same name are joined into a comma-separated string in the Request.Form / Request.QueryString collections - so if there's a hidden field or textbox with name="foo" as well as your <select name="foo">, you'll get the second (empty) value joined to the first, separated by a comma.



回答3:

Are there two form elements with the same name? If you have Firebug installed, it's worth taking a look to see if the data is actually being posted with the commas or if it's happening after ASP gets its awful paws on it.