2011-07-07 13 views
0

私は、これらの4つのフィールド(それぞれ異なる名前&の機能)の約30のインスタンスでフォームデータを処理しています。これをより管理しやすくする方法はありますか?このバグのロジックを最適化するにはどうすればよいですか?

<!--- 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)#"> 
+0

より多くを知らなくても、それはそう。空の文字列を無視するか、特定の引数のために 'default'を設定するなどの機能をもう少し働かせてください。 '#defaultDate#'とは何ですか? (また、 "会社"のチェックは、トリムを超えて何もしないようです)。 – Leigh

+0

あなたはアイテムを複製している場所とその逸脱箇所を確認するために、pastbin(http://www.pastebin.com)コードの大きなサンプルを入手できますか? – Nate

答えて

0

私はあなたが呼び出す関数にデフォルトのパラメータで引数を与え、引数のコレクションとして渡します。

機能:

<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" /> 

呼び出し:あなたが呼び出している関数にそのロジックの一部を移動することができますように

<cfset myFunctionUsingForm(argumentCollection=form) /> 
関連する問題