ColdFusion - 使用带有多个字段和多个提交按钮的cfloop

时间:2013-02-22 16:26:20

标签: coldfusion submit cfform cfpdfform cfloop

我希望使用cfformcfpdfform中的表单值传递给PDF。这是我的小测试页面,它循环显示50条记录以提取名字和姓氏。我想把它们放到pdf字段中。目前,它将所有50个名字放入firstname字段,将所有lastnames放入pdf的lastname字段。我没有与提交按钮结婚,但有哪些更好的选择呢?

在我的最后一次迭代中,我将大约100个领域。

- 表 -

<cfform name="autopdf" method="POST" action="automated_pdf_submit.cfm" enctype="multipart/form-data">
        <h1>Select a state to insert into a PDF form</h1>
        <div class="center">
            <select name="pdfselect" id="pdfselect">
                <option value="" selected>--Select State--</option>                 
                <option value="FROI_NY.pdf">New York</option>
                <option value="FROI_PA.pdf">Pennsylvania</option>
            </select>
            <cfinput type="hidden" name="statevalidate" onValidate="yourFunction" 
                     message="YOU MUST SELECT A STATE TO CONTINUE!">
        </div>
        <table align="center" style="width:400px">
            <tr>
                <th></th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Export to PDF</th>
            </tr>
            <cfoutput>
            <cfloop query="#qryPersons#" startrow="1" endrow="50" >
                <tr class="#IIf(CurrentRow Mod 2, DE('rowOdd'), DE('rowEven'))#" onmouseover="this.className='rowHighlight'" 
                    <cfif CurrentRow Mod 2>onmouseout="this.className='rowOdd'"
                    <cfelse>onmouseout="this.className='rowEven'"</cfif>>
                        <td>#qryPersons.CurrentRow#</td>
                        <td>#qryPersons.LastName#</td>
                        <input type="hidden" name="FirstName" value="#qryPersons.LastName#">
                        <td>#qryPersons.FirstName#</td>
                        <input type="hidden" name="LastName" value="#qryPersons.FirstName#">
                        <td style="width:50px"><input type="submit" value="Create PDF"</td>
                </tr>
            </cfloop>   
            </cfoutput>
        </table>
</cfform>

- 动作 -

<cfpdfform action="populate" source="forms\#form.pdfselect#">
    <cfpdfformparam name="FirstName" value="#form.FirstName#">
    <cfpdfformparam name="LastName" value="#form.LastName#">
</cfpdfform>

1 个答案:

答案 0 :(得分:5)

您的表单字段全部都是FirstNameLastName,您需要将这些字段设为唯一

<cfloop query="#qryPersons#" startrow="1" endrow="50" >
 <tr class="#IIf(CurrentRow Mod 2, DE('rowOdd'), DE('rowEven'))#" onmouseover="this.className='rowHighlight'" 
  <cfif CurrentRow Mod 2>onmouseout="this.className='rowOdd'"
  <cfelse>onmouseout="this.className='rowEven'"</cfif>>
  <td>#qryPersons.CurrentRow#</td>
  <td>#qryPersons.LastName#</td>
  <input type="hidden" name="FirstName#qryPersons.currentrow#" value="#qryPersons.LastName#">
  <td>#qryPersons.FirstName#</td>
  <input type="hidden" name="LastName#qryPersons.currentrow#" value="#qryPersons.FirstName#">
  <td style="width:50px"><input type="submit" value="Create PDF"</td>
  </tr>
</cfloop> 

之前我从未使用过cfpdfform,但这种语法应该可行。您可能还需要动态命名下面的name属性

<cfpdfform action="populate" source="forms\#form.pdfselect#">
 <cfloop from="1" to="50" index="i">
    <cfpdfformparam name="FirstName" value="#form['FirstName'&i]#">
    <cfpdfformparam name="LastName" value="#form['LastName'&i]#">
 </cfloop>
</cfpdfform>