2

I'm looking to pass form values in a cfform to a PDF using cfpdfform. Here's my little test page that loops through 50 records to pull the first and last name. I'm trying to just pull those into the pdf fields. Currently it puts in all 50 of the first names into the firstname field and all of the lastnames into the lastname field of the pdf. I'm not married to the submit button, but what are better options?

In my final iteration of this I'll be pulling in about 100 fields.

--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>
Macness
  • 1,226
  • 2
  • 13
  • 24

1 Answers1

5

Your form fields are all named FirstName and LastName you need to make those unique

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

I've never used cfpdfform before, but this syntax should work. You may need to dynamically name the name attribute below as well

<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>
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • I think he only want's to pass in 1 name at a time, so he should really move the form to be around each one, so he'd have fifty form tags. – Busches Feb 22 '13 at 16:39
  • @matt Wouldn't this create multiple pdfs? I only want to pass the one that I click on. See these two images for reference: http://imgur.com/KZ4HEiE,VIjlgDz – Macness Feb 22 '13 at 16:42
  • then you just need to move the loop outside your form, so you have 50 form fields on your page – Matt Busche Feb 22 '13 at 16:43
  • If you only want to pass one of the names, then you need to reorganize your form. The easiest way, since oyu need to include state, would be to have each submit button with a unique name, so you can only pull in that one. – Busches Feb 22 '13 at 16:43
  • Actually, I think the easiest way is to move the form tags inside the loop. – Dan Bracuk Feb 22 '13 at 16:56
  • 1
    @DanBracuk then you have to include the state selection inside each form. – Busches Feb 22 '13 at 17:13
  • I implemented this but I only get the last record to show up on the PDF. My only change was the submit button as mentioned by @Busches `` – Macness Feb 22 '13 at 18:00