开发者

How can I optimize this buggy logic?

开发者 https://www.devze.com 2023-03-17 22:12 出处:网络
I am dealing with form data with about 30 instances of these sets of 4 fi开发者_运维百科elds (each of different names & function). Is there a way to make this more manageable?

I am dealing with form data with about 30 instances of these sets of 4 fi开发者_运维百科elds (each of different names & function). Is there a way to make this more manageable?

<!--- Lifeguard Instructor --->
<!--- Is the date defined? --->
<cfif len(Trim(form.lifeguardInstrcutorExp)) EQ 0>
    <cfinvokeargument name="lifeguardInstrcutorExp" 
        value="#defaultDate#">
<cfelse>
    <cfinvokeargument name="lifeguardInstrcutorExp" 
        value="#CreateODBCDate(Form.lifeguardInstrcutorExp)#">
</cfif>
<!--- Is a Company defined? --->
<cfif len(Trim(form.lifeguardInstrcutorCompany)) EQ 0>
    <cfinvokeargument name="lifeguardInstrcutorCompany" value="">
<cfelse>
    <cfinvokeargument name="lifeguardInstrcutorCompany" 
        value="#Trim(Form.lifeguardInstrcutorCompany)#">
</cfif>
<!--- Has a file been specificed? --->
<cfif not len(Trim(form.lifeguardInstrcutorImage)) EQ 0>
    <cffile action="upload" accept="#defaultFileAccepted#" 
        filefield="lifeguardInstrcutorImage" 
        destination="#destination#" 
        nameConflict="makeUnique">
    <cfinvokeargument name="lifeguardInstrcutorImage" 
        value="#pathOfFile##cffile.serverFile#">
<cfelse>
</cfif>
<!--- Do We have a hard copy? --->
<cfinvokeargument name="lifeguardInstrcutorOnFile" 
    value="#Trim(form.lifeguardInstrcutorOnFile)#">


I would have the function you are invoking have arguments with default parameters, and then pass the form as the argument collection.

Function:

<cffunction name="myFunctionUsingForm">
        <cfargument name"lifeguardInstructorExp" type="string" default="#defaultDate#" />
        <cfargument name"lifeguardInstrcutorCompany" type="string" default="" />
        <cfargument name"lifeguardInstrcutorImage" type="any" default="" />
        <cfargument name"lifeguardInstrcutorOnFile" type="boolean" default="false" />

Invocation:

<cfset myFunctionUsingForm(argumentCollection=form) />
0

精彩评论

暂无评论...
验证码 换一张
取 消