form.fieldnames gotcha
Today I was working on a form. One of my text fields is named "training_date". When I submit the form, here is what I see when dumping the Form struct.
ADDRESS myaddress
EMAIL mail@email.com
EMPLOYER scur
FIELDNAMES NAME,EMPLOYER,ADDRESS,PHONE,EMAIL,TRAINING_LOCATION,SUBMIT
NAME troy
PHONE 2223333
SUBMIT Submit
TRAINING_DATE 1/2/05
TRAINING_LOCATION roseville
Notice in the data dump that we see a value for the field "1/2/05" - this is good and expected. However, the field TRAINING_DATE is not listed in the FIELDNAMES key - this is bad. It was bugging me, as I needed to loop over that list. The weird thing is I could change the fieldname to "training_dat" or "training_date1" and it was working. After being stumped for about 15 minutes I showed it to a co-worker. He recognized it was probably the "_date", did a quick google search, and found the answer.
Here's a snippet from the<cfform> livedocs.
Any form field name, from the cfform tag or an HTML form, that ends in one of the following suffixes invokes server-side form validation:
* _integer Verifies that the user entered a number.
* _float Verifies that the user entered a number.
* _range Verifies that a numeric value entered is within specified boundaries.
* _date Verifies that the user entered a date; converts to ODBC date format.
* _time Verifies that the user correctly entered a time; converts to ODBC time format.
* _eurodate Verifies that the user entered a date in a standard European date format; converts to ODBC date format.
Do not use these suffixes for your field names.
ADDRESS myaddress
EMAIL mail@email.com
EMPLOYER scur
FIELDNAMES NAME,EMPLOYER,ADDRESS,PHONE,EMAIL,TRAINING_LOCATION,SUBMIT
NAME troy
PHONE 2223333
SUBMIT Submit
TRAINING_DATE 1/2/05
TRAINING_LOCATION roseville
Notice in the data dump that we see a value for the field "1/2/05" - this is good and expected. However, the field TRAINING_DATE is not listed in the FIELDNAMES key - this is bad. It was bugging me, as I needed to loop over that list. The weird thing is I could change the fieldname to "training_dat" or "training_date1" and it was working. After being stumped for about 15 minutes I showed it to a co-worker. He recognized it was probably the "_date", did a quick google search, and found the answer.
Here's a snippet from the
Any form field name, from the cfform tag or an HTML form, that ends in one of the following suffixes invokes server-side form validation:
* _integer Verifies that the user entered a number.
* _float Verifies that the user entered a number.
* _range Verifies that a numeric value entered is within specified boundaries.
* _date Verifies that the user entered a date; converts to ODBC date format.
* _time Verifies that the user correctly entered a time; converts to ODBC time format.
* _eurodate Verifies that the user entered a date in a standard European date format; converts to ODBC date format.
Do not use these suffixes for your field names.


<< Home