Skip navigation
Thytar
Currently Being Moderated

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

Nov 29, 2012 9:30 AM

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!

 
Replies
  • Currently Being Moderated
    Dec 3, 2012 9:48 AM   in reply to Thytar

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

    right(fieldname,4) eq 'date'

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 3, 2012 4:01 PM   in reply to Thytar

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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 4, 2012 9:28 AM   in reply to Thytar

    That's pretty vague. 

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 4, 2012 11:14 AM   in reply to Thytar

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points