Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
You could build a dynamic query which only updates the fieldnames with
right(fieldname,4) eq 'date'
Copy link to clipboard
Copied
You can cfloop through form.fieldnames and if the index contains the string "date", do something with it.
Copy link to clipboard
Copied
Yes... but that is the part I need help with.
Copy link to clipboard
Copied
That's pretty vague.
Copy link to clipboard
Copied
@ Dan Bracuk
Yes... you are correct. It is vague.
Mostly because I am a hack, and I have never written any of my own code.
I have only taken what I could find and edit it to make it work for my purposes.
I am totally guessing at what I think the code would look like and could work.
I was HOPING that someone like BKBK would come along... and tell me
that my approach is all wrong or re-write it for me so that it would work.
Which he did exactly that!
Thank you for your responses. I do appreciate your help!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@ 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!