Coldfusion is 100% case-insensitive so you wont get the right casing
from the form struct.  One way to handle it might be to shadow all of
your form fields with a hidden input called "fields" like this:

<form action="" method="post">
<input name="firstName" type="text" size="20" />
<input name="fields" type="hidden" value="firstName" />

<input name="lastName" type="text" size="20" />
<input name="fields" type="hidden" value="lastName" />

<input type="submit" value="Submit Me" />
</form>

when you submit it you will have the following three form variables:
#FORM.FIRSTNAME#, #FORM.LASTNAME#, #FORM.FIELDS#

and #FORM.FIELDS# will be a comma-delimited ordered-list of form fields
with the casing you desire. "firstName,lastName"

an even SLICKER way to go would be to have a standard _javascript_
function iterate through the form fields and write the list in a hidden
value during an onSubmit.  If you want I can write that function for
you.  Just pay me via paypal... :-P *joke*

Here's a working example you can use.  (Please note that the hidden
input field on the form, "fieldList" is camelCased.  If you change the
case of that field, make sure you change the case in the function too.
Other than that try it out on a coldfusion page and be amazed.)

<!--- BEGIN FIELDLIST SOLUTION CODE --->
<script language="_javascript_" type="text/_javascript_">
// this _javascript_ function iterates through the
// fields aka "elements" of the form and updates
// the hidden element called "fieldList" with any
// field names encountered, keeping the proper case
// since some people want strict casing info on their
// fields apparently!  ;-P
function UpdateFieldList(formRef) {
var fieldList='';
for(i=0;i<formRef.elements.length;i++) {
if((formRef.elements[i].name!='')
&& (formRef.elements[i].name!='fieldList')) {
if(fieldList!='') fieldList=fieldList+',';
fieldList=fieldList+formRef.elements[i].name;
}
}
formRef.fieldList.value=fieldList;
}
</script>
<form name="myForm" action="" method="post">
<input type="hidden" name="fieldList" value="" />
<input type="text" name="firstName" value="J0e" />
<input type="text" name="LaSTnAMe" value="Hax0r" />
<input type="submit" value="SUBMIT ME, PLEASE!" />
</form>
<script language="_javascript_" type="text/_javascript_">
// it is important that this function call is made
// only used AFTER the form is already available, i.e.
// written to the page.  You could throw it in the
// form's onSubmit event too, if you wanted.
UpdateFieldList(document.forms.myForm);
</script>
<!--- END FIELDLIST SOLUTION CODE --->

-----Original Message-----
From: Dave Carabetta [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 02, 2004 11:01 AM
To: CF-Talk
Subject: Form Field Submission Casing

I have what I feel like is a basic question, but for some reason I can't

figure this out. I have a basic form where I output a list of name/value

pairs for editing (i.e., name=value). However, I am dependent on
maintaining
the casing of the var name. I have made the form field name the name of
the
variable, but when I post the form, all the field names come in upper
cased.
I want to be able to do something like this:

<cfloop collection="#Form#" item="formField">
  #formField#=#Form[formField]#
</cfloop>

but the #formField# casing is always "NAME" instead of "Name" or "name".
I
have tried a number of different ways of getting at the form field namew

(the above way, looping over the Form.fieldnames variable, using
cfscript's
"for fieldname in Form" syntax), but it's always upper cased. Is there a
way
to preserve the casing? I really don't want to have to create a
structure
mapping or some such workaround with the properly cased names if it's
not
necessary.

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to