2013-02-22 28 views
2

我在尋找使用cfpdfformcfform中的表單值傳遞給PDF。這裏是我的小測試頁面,循環訪問50條記錄來拉取姓氏和名字。我試圖把它們拉入pdf領域。目前它將所有50個名字放入firstname字段中,並將所有lastname放入pdf的lastname字段中。我沒有與提交按鈕結婚,但有什麼更好的選擇?ColdFusion - 使用帶多個字段和多個提交按鈕的cfloop

在我的最後一次迭代中,我將拉入大約100個字段。

--Form--

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

--Action--

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

這裏有什麼問題?這聽起來像是你的問題正在起作用。 – Busches 2013-02-22 16:33:54

+0

@Busches它將所有的名字拉入表單。這裏是頁面和PDF格式的圖片:http://imgur.com/KZ4HEiE,VIjlgDz – Macness 2013-02-22 16:37:56

+0

啊,那麼馬特的答案會解決你的問題。 – Busches 2013-02-22 16:38:47

回答

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> 
+0

我想他一次只想傳一個名字,所以他應該將表格移動到每一個名字的周圍,所以他會有五十個表格標籤。 – Busches 2013-02-22 16:39:18

+0

@matt這不會創建多個pdf文件嗎?我只想通過我點擊的那個。看到這兩個圖像作爲參考:http://imgur.com/KZ4HEiE,VIjlgDz – Macness 2013-02-22 16:42:34

+0

然後你只需要移動窗體外的循環,所以你有50個表單域 – 2013-02-22 16:43:30