Last Friday I posted a problem that I was having and with the help of 
Hatton, who got me pointed in the right direction, and Leigh (his posts 
show up as CS) who extended it a bit, it is now working. I am going to 
post the results here but I will quickly explain what I was doing.

There are a series of forms that are pulled from a database using an CMS 
system. When the forms are submitted, the user wanted a PDF emailed that 
looks exactly like the form, except of course the input elements are 
replaced with the submitted values. The easy way out would be to create 
a separate action page for each form, but that was not the solution they 
were looking for. Basically I needed everything to go to one file, and 
regardless of what form was submitted, the same file processes each one. 
The biggest headache was that all the forms are checklists, and thus 
each row has three radio buttons. There are also some forms with text 
fields, text areas and select lists. I could extract the text and even 
get the filled values to show up, but I could not get the cells to line 
up with their respective columns (a radio in column three, cell 1 would 
show up in column one, cell 1 and crap like that). So anyway, like I 
said, Leigh got it to work for me and I want to post the information in 
case anyone else runs across this issue.

Bruce

<cfloop query="getContentObjectData">
        <!--- Now we need strip out all the form elements and replace 
them with what was submitted --->
           <!--- first remove open/close form tags --->
        <cfset NewContentBlock = 
REReplace(contentBlock,"</*form[^>]*>","","ALL")>
          <!--- Remove the hidden fields, otherwise they show up in the 
header --->
        <cfset NewContentBlock = 
#REReplaceNoCase(NewContentBlock,'<input\s+[^>]*hidden[^>]*>', "","ALL")#>
        <!--- get an array of all input tags --->
        <cfset matches = reMatchNoCase('<input\s+[^>]*>', NewContentBlock)>
              
        <!--- for each input field ... --->
        <cfloop array="#matches#" index="element">
            <!--- initialize a structure for storing input field 
properties --->
            <cfset htmlField = {} >
                   
            <!--- extract field properties: name, value AND type (if 
exists) --->
            <cfset params = 
reMatchNoCase('((name|value|type)=\"[^\"]*\")', element)>
            <cfloop array="#params#" index="pair">
                <cfif listLen(pair, "=")>
                    <cfset htmlField[listFirst(pair, "=")] = 
replace(listLast(pair, "="), '"', "", "all")>
                </cfif>
            </cfloop>

            <!--- verify this field was submitted in the current form --->
            <cfset fieldExists = structKeyExists(htmlField, "name") AND 
structKeyExists(form, htmlField.name)>
            <cfset isRadioButton = structKeyExists(htmlField, "type") 
AND htmlField.type is "radio">

            <!--- if the field exists ... --->
            <cfset newValue = "">
            <cfif fieldExists>
                <cfif isRadioButton>
                    <!--- AND it was the selected button, replace it 
with an "X" --->
                    <cfif structKeyExists(htmlField, "value") AND 
htmlField.value EQ form[htmlField.name]>
                        <cfset newValue = "x">
                    <cfelse>   
                        <cfset newValue = "&nbsp;"> <!--- This is done 
so that the form looks like the original, except instead of an X we 
enter a non-breaking space --->
                    </cfif>
                <!--- otherwise, assume it is a text field and replace 
it with the field value --->
                <cfelse>
                    <cfset newValue = form[htmlField.name]>
                </cfif>   
            </cfif>
               
            <!---- do the actual replace --->          
            <cfset NewContentBlock = reReplaceNoCase(NewContentBlock, 
element, newValue, 'all')>
        </cfloop>
    </cfloop>

Once this is done I put everything inside a cfsavecontent tag, then use 
CFDOCUMENT and create the PDF on the file system, and then attach it to 
an email.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:302021
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to