Creating Temporary Fields in Web Forms
There are a few ways I've seen of displaying field-like inputs on the web without storing them in the submitted document, but I think what I'm about to describe is the easiest way of all.
Basically you don't give the field a name, but give it an ID instead. For example:
<input id="ToDo_tmp" type="text" />
In the browser this looks and acts like a real field. However, when you come to submit the form it isn't counted as a "Successful Control" and its name/value isn't sent to the server.
These kind of fields are really useful sometimes. As a simple example take the ToDo list form from the other week. As I mentioned then, the code added the given value to a set of hidden fields, all with the same name, which can be saved in a multi-value field.
Imagine we had a real field on our form called "ToDo" with "type="\hidden\"" in its HTML Attributes. This field is multi-value and separated by semi-colons. Using a clickable button, JavaScript and our temporary field we can add its values like so:
oFrm["ToDo"].value+=(document.getElementById("ToDo_tmp").value)+";"
Or, for you Prototype fans:
$("ToDo").value+=$F("ToDo_tmp")+";"
Obviously not a great example, but you get the idea, right? To add the temporary field you can use PassThru HTML and you can even give it a value using Computed Text. Note that this applies to all field types. Not just plain text ones.
That's handy. I don't think I've used that particular exploit before. With the prevalence of operating on field id's, however, I wonder how long before some browser decides this is equivalent to a field name. Nice tip though.
Jerry. As I understand it the browser should only submit the field to the server if the name is given. If a browser to send an id/value pair it's breaking the W3C guidelines.
Isn't name a required attribute - meaning that this would cause a page to fail vailidation?
Hi Peter. I just ran this page through the W3C validator and it didn't mention it.
This is an awesome method to allow browser-only fields for UI functionality without cluttering up your document with 30 fields that have a "tmp_" prefix. Good stuff!