Skip to main content
Inspiring
May 15, 2024
Answered

Form fieldnames missing element

  • May 15, 2024
  • 3 replies
  • 1425 views

Hello -

 

Has anyone ever seen CFDUMP  - form, not display all the fieldnames with data in it?

 

I have a number of formfields, but not A LOT of them and one of the names is missing.

 

Anyway, I have attached a CFDUMP of the form fields...

The field in question should be the last one in the list, it should be journal_date.

It doesn't exist in the list of fieldnames, but the value does exist.

 

Anybody have an idea of what's happening?

 

Thanks

 

Doug

    This topic has been closed for replies.
    Correct answer Charlie Arehart

    Well, no. I did understand it completely, having read your note and Dave's before I replied. 

     

    I meant what I said, that the problem (of the field not being in the form.fieldnames) not happening for me except in cf10 (which would jive with the so post from so long ago). FWIW, I tested _date and _required. I didn't show code as it seemed everyone was on the same page.

     

    So are you saying you tested things and confirm what he saw? As I asked him, I'll be curious what cf version and update that's on. 

    3 replies

    Charlie Arehart
    Community Expert
    Community Expert
    May 15, 2024

    While Dave and BKBK are right about the explanation and workaround, I'll not that I tried this on all versions back to 10 (all at their latest available updates), and the problem you describe does not happen for me on any but cf10.

     

    So i'm curious to hear what version you're on, and what update of that. 

    /Charlie (troubleshooter, carehart. org)
    BKBK
    Community Expert
    Community Expert
    May 16, 2024

    Charlie, I suspect that you misunderstand it as I, too, did initially. The issue is not about the form field xxx_date. It is about the list form.fieldnames. 

     

    Apparently, when a form field is named xxx_date, then that name is missing from the list form.fieldnames. This has been known for quite some time. The Stackoverflow link in my previous post points to a report of the issue over 15 years ago.

     

    It is clear that, regarding form field names, ColdFusion treats words that end in _date as reserved words.  In fact, the same goes for words ending in _integer ,_time ,_eurodate ,_range or _float, as the following demonstration shows.

    That this has to do with validation is no surprise. The name endings, integer, time, date, etc., are among the values of the type attribute of the isValid function.

     

    Demo:

    • Launch the CFM page and press the submit button.

     

    <cfif structKeyExists(form, "fieldnames")>
    	<h2>
    		Field names in <i>form.fieldnames</i>
    	</h2>
    	<p>
    	<cfscript>
    		// The list form.fieldnames
           fieldNamesList=form.fieldnames;
           closure=function(item){ 
                  WriteOutput( item & "<br>"); // list each item on separate line
           }
           fieldNamesMap=listMap(fieldNamesList,closure);
           
    	</cfscript>
    	
    	<h2>
    		Field names not in <i>form.fieldnames</i>
    	</h2>
    	<p>
    	<cfscript>
    		//The form fields not in form.fieldsname
           closure=function(key, value){ 
                  if (!listContainsNoCase(fieldNamesList, key)){
                  	// list on separate line each not in fieldNamesList
                  	WriteOutput( key & "<br>"); 
                  }
           }
            formFieldsMap=structMap(form,closure);
    	</cfscript>
    	</p>
    <cfelse>
    
    	<p>
    	<cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
    		
    	xxx_array: <input type="text" name="xxx_array"><br>
    	xxx_boolean: <input type="text" name="xxx_boolean"><br>
    	xxx_creditcard: <input type="text" name="xxx_creditcard"><br>
    	xxx_date: <input type="text" name="xxx_date"><br>
    	xxx_eurodate: <input type="text" name="xxx_eurodate"><br>
    	xxx_email: <input type="text" name="xxx_email"><br>
    	xxx_float: <input type="text" name="xxx_float"><br>
    	xxx_guid: <input type="text" name="xxx_guid"><br>
    	xxx_integer<input type="text" name="xxx_integer"><br>
    	xxx_numeric<input type="text" name="xxx_numeric"><br>
    	xxx_query: <input type="text" name="xxx_query"><br>
    	xxx_range: <input type="text" name="xxx_range"><br>
    	xxx_regex: <input type="text" name="xxx_regex"><br>
    	xxx_ssn: <input type="text" name="xxx_ssn"><br>
    	xxx_string: <input type="text" name="xxx_string"><br>
    	xxx_struct: <input type="text" name="xxx_struct"><br>
    	xxx_telephone: <input type="text" name="xxx_telephone"><br>
    	xxx_time: <input type="text" name="xxx_time"><br>
    	xxx_uuid: <input type="text" name="xxx_uuid"><br>
    	xxx_usdate: <input type="text" name="xxx_usdate"><br>
    	xxx_xml: <input type="text" name="xxx_xml"><br>
    	xxx_zipcode: <input type="text" name="xxx_zipcode"><br>
    	
    	<br><input type="submit" name="submitForm" value="submit">
    	</form>	
    	</p>
    </cfif>
     
    
    <cfdump var="#form#" >

     

     

    Result:

    On the subject of form field names, there is yet another curiosity. ColdFusion treats words that end in _required as reserved words. 

    Charlie Arehart
    Community Expert
    Charlie ArehartCommunity ExpertCorrect answer
    Community Expert
    May 16, 2024

    Well, no. I did understand it completely, having read your note and Dave's before I replied. 

     

    I meant what I said, that the problem (of the field not being in the form.fieldnames) not happening for me except in cf10 (which would jive with the so post from so long ago). FWIW, I tested _date and _required. I didn't show code as it seemed everyone was on the same page.

     

    So are you saying you tested things and confirm what he saw? As I asked him, I'll be curious what cf version and update that's on. 

    /Charlie (troubleshooter, carehart. org)
    BKBK
    Community Expert
    Community Expert
    May 15, 2024

    I initially misunderstood the issue you describe. What I now understand is that journal_date is missing from the list form.fieldnames. If so, then it would seem that this is a bug. Unless, of course, ColdFusion reserves field names such as xxx_date for validation. See https://stackoverflow.com/questions/592076/value-missing-from-form-fieldnames-in-coldfusion 

    Inspiring
    May 15, 2024

    Ok... I did some additional testing... I changed the fieldname from journal_date to journal_date1, and that was included in the form.fieldnames.

     

    Does anyone know if journal_date is reserved?

     

    Thanks

    Doug

    Community Expert
    May 15, 2024

    Not exactly reserved, but it's intended for use with CF's server-side validation. The field name  "example_date" is used to ensure "example" is a date. There are a handful of these validation suffixes. They've been around since a very early version of CF - maybe 2.0?

     

    Dave Watts, Eidolon LLC 

    Dave Watts, Eidolon LLC