HTML form values adding commas in Classic ASP - html

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)

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

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.

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.

Related

Is it possible to have Chrome store two (or more) values with the same name attribute a by just one form submit?

Sorry, I had a hard time trying to word my question properly so here is an actual example.
<form>
<input name="publication_year">
<input name="publication_year">
<input type="submit">
</form>
So when user submits, say, 1984 and 2022 in the two fields respectively Chrome stores only 1984 in the "automatic form fill storage" even though two different values are paired with the same name attribute. In order to storage multiple values I have to change the value in the first input and submit the form again.
But is there a way to store two values at the same time - so that Chrome would suggest both these values the next time I click on an input field that shares the same name attribute?

What is the REGEX for ALAA-123456

I'm a newbie at php.
HTML form is capturing data and mailing it to user via php.
I am trying to make this field have a default value of "ALAA-" and then only permit 6 numbers after "ALAA-". I believe I need the REGex for this but I can't figure out the code. thank you!
<div class="form-group">
<label for="form_moms_alaa_registration">Doodle Mom's ALAA Number *11
digits</label>
<input id="form_moms_alaa_registration" type="text" pattern=""
default="ALAA-123456" tabindex="5" value="ALAA-"
name="inputmomsalaaregistration" class="form-control"
placeholder="ALAA-######" data-error="Doodle Moms ALAA registration
should have 6 numbers. It is a required field." required>
<div class="help-block with-errors"></div>
</div>
While sending your client-side HTML form PHP will get the values sent with the tag how the post method , but first I suggest using a JQuery script to validate the upload data see more information to get values in HTML attributes:
help about get attribute value
For the server side, PHP manipulates variables that you can treat this value using regex:
preg_match('/ALAA-[0-9]{6}/', $_POST['YOURFIELD'], $matches);
Here is the regex you need
pattern="ALAA-\d{6}"
You could also write it as:
pattern="ALAA-[0-9]{6}"
I don't think either is more correct than the other, but some people might have opinions about which is more readable.
\d means match any digit. [0-9] means match any character in the range of 0-9 so that is effectively the same thing as \d
The {6} means match exactly 6 repetitions of the preceding character

Distinguish between missing and an unchecked checkbox

I was under the impression that the server code (or at least PHP) that parses the POST of an HTML form cannot distinguish between a POST from a form with a checkbox whose value is not "checked" versus a POST from a form that doesn't include a checkbox by that name at all.
For example, take the following 3 forms. If they were all submitted as is, with no manual entry, just using the inital values, then forms f2 and f3 would send the same results:
<form name="f1">
<input type="text" name="txt_1" value="Hello">
<input type="checkbox" name="chk_1" checked="checked">
</form>
<form name="f2">
<input type="text" name="txt_1" value="Hello">
<input type="checkbox" name="chk_1">
</form>
<form name="f3">
<input type="text" name="txt_1" value="Hello">
</form>
In my real application, I'm submitting forms of the type f3, with a checkbox deliberately omitted (different checkboxes in different situations). For any checkbox I left missing, I wanted the back-end to just ignore it -- don't treat it as On or Off, just do nothing related to that field.
After I built it, I was almost going to throw out my work before testing, when I remembered that the back-end would treat a missing chk_1 exactly like it would an existing chk_1 that was unchecked -- and would turn Off the related value in the back-end.
But I went and tried it out, and IT WORKED! And I tried different variations, and they all work. They correctly disregard the fields related to missing checkboxes (while processing the fields related to existing checkboxes).
So, that's great, but I don't know how it's done (or whether it might stop working -- say on another browser, etc.). In PHP, I know that the code isset($_POST['chk_1']) will get the value of the checkbox, and it returns false in both cases: unchecked checkbox or missing checkbox. Is there a way in other server languages to distinguish? Why is this working?
The short answer is that PHP only gets what the Browser sends it. It doesn’t know or care about the form itself, just the data from the browser. The data comes as a collection of name=data values.
Among other factors, the browser will only send a button if
it has a name, and
it has been selected
If the button has no name, or if it was not selected, then PHP will never hear of it. This applies to
normal buttons (<button> or <input type="submit">)
radio buttons (where only one in a group can be selected: if none is selected, then this, too, will be absent)
checkboxes (only selected checkboxes are sent)
So, the short answer is that PHP will never know whether a checkbox is missing or simply unchecked, because neither will be sent to the server.

What is the purpose of the `name` attribute in a checkbox input element?

I went through many online documents for the checkbox input in XHTML. Can anyone clear my doubt? What does this name field actually stand for?
Milk: <input type="checkbox" name="checkbox" value="Milk">
Chocolate: <input type="checkbox" name="checkbox" value="chocolate">
Cold Drink: <input type="checkbox" name="checkbox" value="Cold Drink">
I thought it was an identifier for that particular checkbox, which can later be used in other file by just referring their name, but given that all the checkbox had same name, why even specify it? A little confused of this.
Dont be confused because of name="checkbox". It could more logically be name="drink" and type=checkbox.
In the above case, you have multiple checkboxes with the same name. When several checkboxes have the same name, the form will send a group of values to the server in the request. Note: only the values of the checked checkboxes will be sent to the server.
Ideally these are used to allow multiple choice questions where more than one answer is allowed.
As opposed to radio buttons, where only one answer is allowed among the options.
Update:
On the receiving side, if you're using JSP for example - the values of the selected checkboxes will be available as request.getParameterValues("drink") or request.getParameterValues("checkbox") in your actual case. This is where the name attribute is used.
The name attribute is used to
reference form data after it’s
submitted, and to reference the data
using JavaScript on the client side.
Source: http://reference.sitepoint.com/html/input/name
Basically, what you've described. When the form is submitted, you can access the values of the form elements through the name you ascribe to them.
The only place where you would want to have multiple inputs with the same name is when they are radio buttons, in which case it is used to indicate which one of them belongs to the same group and thus only one of which can be selected at a time.
The name attribute is used to identify a checkbox. Which you could parse into a object like so {checkboxName1: 'checkboxValue2', checkboxName2: 'checkboxValue2'}
You missed the array setting for the name. By using the array setting (using square brackets), the result will be three different indexes for the checkboxes.
Milk: <input type="checkbox" name="checkbox[]" value="Milk">
Chocolate: <input type="checkbox" name="checkbox[]" value="chocolate">
Cold Drink: <input type="checkbox" name="checkbox[]" value="Cold Drink">
the "name" is same with the databse record, every field should have a name, so when you click the submit, the data will recorded to the database~~~~~

Auto-append items from a select list

I have a list of different items within a select multiple list and I want to auto-append to a form that a user submits.
HTML of category multiple select list:
<select name="category[]" size="4" multiple="multiple" id="group">
<option value='7'>Faculty</option>
<option value='8'>Staff</option>
<option value='6'>Students</option>
</select>
I want to do something like:
<input type="hidden" name="category[7,8]" />
This will automatically assign the submission to the appropriate selected list items from within category[], without them ever seeing it.
This is stored within a database, so I need to accomplish it this way.
I know this does not work, but this should give you an idea of what I am trying to do.
A successful multiple-select control just gets submitted as having multiple values. E.g., if you selected "Faculty" and "Staff" in your list, what gets submitted is something like:
category[]=7&category[]=8
You can replicate this (at least in Firefox, haven't tested elsewhere) with two hidden inputs:
<input name="category[]" value="7" type="hidden"/>
<input name="category[]" value="8" type="hidden"/>
I believe this could be accomplished using a Javascript library (such as jQuery) to handle the change on the Selections and append/update the items in your hidden field. You could then also use Ajax to update your database with the selection when necessary.
Your specific requirements might not allow for the above though. Some additional information would be helpful for those viewing such as what backend you're using (php, asp.net, or if it is just static html) and if you are currently using javascript (or a library) to assist you in any other tasks.
I'll try to check back on updates to see if I can be of more specific help. (Note: I think I'm too low of reputation to be able to post this as a comment at the moment so had to do an answer instead.)