Skip to main content
Participant
November 29, 2012
Question

What is the easiest way to change the ouput of all dateField at once?

  • November 29, 2012
  • 3 replies
  • 922 views

I am a newbie, limited Coldfusion.

I have a very large form with 33 dateField entries.

I am working towards being more modular and trying to have only one place to edit items.

I have a new patient form that post to a new patient PARSER page.

(our server is now using Coldfusion 10)

I edit in Dreamweaver CS6

I was wanting to use something like this:

        <!--- this controls all date output --->

        <cfparam name="#form.*Date# = dateModOutput">

        <cfparam name="dateModOutput = DateFormat(form.*Date,"mmm/dd/yyyy")">

The form.*Date would effect ALL DATEFIELD entries in the form

such as...

#CTScanDate#

#MRIScanDate#

#BoneScanDate#

and so on...

Any code that would effectively do this is fine.

My boss said it can't be done... but I believe anything is possible and that this is probably very simple and easy.

Thank you for any and all help!

I am really starting to enjoy Coldfusion and its power!

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    December 4, 2012

    Thytar wrote:

    I was wanting to use something like this:

            <!--- this controls all date output --->

            <cfparam name="#form.*Date# = dateModOutput">

            <cfparam name="dateModOutput = DateFormat(form.*Date,"mmm/dd/yyyy")">

    Your cfparam syntax seems strange to me. I would aim for something like <cfparam name="form.CTScanDate" default="#DateFormat(now(),'mmm/dd/yyyy')#">. Here, I have set form.CTScanDate by default to today's date.

    The form.*Date would effect ALL DATEFIELD entries in the form

    such as...

    #CTScanDate#

    #MRIScanDate#

    #BoneScanDate#

    and so on...

    Any code that would effectively do this is fine.

    My boss said it can't be done... but I believe anything is possible and that this is probably very simple and easy.

    Your boss is right. Partly. So are you. It can be done, however not by placing wildcards into form field names. I would follow the way Dan Bracuk pointed out, and do something like this:

    <cfset formFieldNames = "CTScanDate,MRIScanDate,BoneScanDate">

    <!--- Loop through list of field names --->

    <cfloop list="#formFieldNames#" index="fieldName">

    <!--- Pick out field names that end in 'date' --->   

    <cfif len(fieldName) GTE 4 and right(fieldName,4) is "date">

    <cfparam name="form[fieldname]" default="#DateFormat(now(),'mmm/dd/yyyy')#">

    </cfif>

    </cfloop>

    <cfdump var="#form#">

    I have assumed the form has not yet been submitted. Otherwise you wouldn't have to cfparam anything.

    ThytarAuthor
    Participant
    December 4, 2012

    @ BKBK

    Thank you!

    This code is above my head!

    But, you have done exactly what I was hoping someone would do.

    Point out were my approach is wrong and point me in the RIGHT direction.

    I will sit down with my Boss and hopefully

    he can take this and run with it.

    Thank you very much!

    I will get back with you on how me make out!

    Inspiring
    December 4, 2012

    You can cfloop through form.fieldnames and if the index contains the string "date", do something with it.

    ThytarAuthor
    Participant
    December 4, 2012

    Yes... but that is the part I need help with.

    Inspiring
    December 4, 2012

    That's pretty vague. 

    Participating Frequently
    December 3, 2012

    You could build a dynamic query which only updates the fieldnames with

    right(fieldname,4) eq 'date'