首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ColdFusion -使用具有多个字段和多个提交按钮的cfloop

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

Stack Overflow用户
提问于 2013-02-23 00:26:20
回答 1查看 789关注 0票数 2

我希望使用cfpdfformcfform中的表单值传递给PDF。这是我的小测试页面,它循环遍历50条记录来提取名字和姓氏。我正试着把它们放到pdf字段中。目前,它将所有50个名字放入名字字段,将所有姓氏放入pdf的姓氏字段。我不喜欢submit按钮,但是还有什么更好的选择呢?

在我的最后一次迭代中,我将拉入大约100个字段。

--表格--

代码语言:javascript
复制
<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>

--动作--

代码语言:javascript
复制
<cfpdfform action="populate" source="forms\#form.pdfselect#">
    <cfpdfformparam name="FirstName" value="#form.FirstName#">
    <cfpdfformparam name="LastName" value="#form.LastName#">
</cfpdfform>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-23 00:36:56

您的表单域都被命名为FirstNameLastName,您需要使它们唯一

代码语言:javascript
复制
<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属性

代码语言:javascript
复制
<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>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15028753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档