我有一个在表单内部有一个循环的表单。我正在尝试为表单创建动态验证但是失败了,因为当表单提交它时只验证最后一个循环。我研究并尝试了许多不同的场景,当然,都失败了!任何帮助或指示将不胜感激!
<cfform name="form" id="form" method="post">
<cfset Peoplecount = 1>
<cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
<div class="clearfix">
<cfinput type="text" name="firstname_#Add#" id="firstname_#Add#" placeholder="First" validateat="onSubmit" validate="noblanks" message="Please enter owner #Peoplecount#'s first name." value="#evaluate("session.checkout.info.firstname_#Add#")#">
<cfinput type="text" name="middlename_#Add#" id="middlename_#Add#" placeholder="Middle" value="#evaluate("session.checkout.info.middlename_#Add#")#">
<cfinput type="text" name="lastname_#Add#" id="lastname_#Add#" placeholder="Last" validateat="onSubmit" validate="noblanks" message="Please enter owner #Peoplecount#'s last name." value="#evaluate("session.checkout.info.lastname_#Add#")#">
</div>
<script type="text/javascript">
function Validate<cfoutput>#Add#</cfoutput>() {
$('#firstname_<cfoutput>#Add#</cfoutput>').prop('required',true);
$('#middlename_<cfoutput>#Add#</cfoutput>').prop('required',false);
$('#lastname_<cfoutput>#Add#</cfoutput>').prop('required',true);
}
</script>
<cfinput type="submit" name="Submit" value="Submit" onClick="Validate<cfoutput>#Add#</cfoutput>();">
另外我觉得令人困惑的是,如果循环是1,一切正常,但如果循环是任何大于1的数字,那么它只验证最后一个循环
当它像这样:
function Validate() {
<cfinput type="submit" name="Submit" value="Submit" onClick="Validate();">
循环就像这样:
<cfif Add NEQ session.checkout.quantity.pcount>
<div class="labelspace">
<label for="andor_<cfoutput>#Add#</cfoutput>"><strong>Please indicate if "or" or "and" is to be shown on title when issued.</strong></label>
<cfinclude template="../../../ddl/andor.cfm" >
</div><br>
<cfelse>
<cfinput type="submit" name="Submit" value="Submit" onClick="Validate();">
</cfif>
<cfset Peoplecount = PeopleCount + 1>
</cfloop>
答案 0 :(得分:1)
在没有看到你结束cfloop的地方,我只是假设在这里。但是,让我们说cfloop就在代码的最后。您最终会得到多个提交按钮,其中每个按钮都只会&#34;验证&#34;每个提交按钮每3个输入。
以下是我的建议:
<cfinput>
并使用<input>
required="required"
evaluate()
。而是执行此操作value="#session.checkout.info["lastname_" & Add]#"