#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    60
    Rep Power
    5

    Cfdocument and variables


    I'm creating a PDF from Flash which I then print using cfprint. A simplified version of the function is:

    <cffunction name="printPO" access="remote" output="false">
    <cfargument name="p1" type="string" required="yes">
    <cfset replyStruct = StructNew()>
    <cfdocument format="pdf" name="poPdf">
    <P>#p1#</P>
    <h3><U>FROM:</U></h3>
    <P>testcompany,<BR>
    4 Smith Street,<BR>
    Melbourne, Victoria,<BR>
    Australia 3000<BR>
    </cfdocument>
    <cfprint source="poPdf" printer="hp LaserJet 4300">
    <cfset replyStruct.status = "ALLOK">
    <cfset replyStruct.param = #p1#>
    <cfreturn replyStruct>
    </cffunction>

    The whole process essentially works with the p1 parameter being passed back correctly and the pdf printing. The problem is that the p1 variable prints as the literal 'p1' instead of the contents of the variable p1. I presume I'm defining it incorrectly, so what is the correct syntax? Do I need to use cfoutput in order to 'evaluate' the variables?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    Try wrapping it in cfoutput, and also confirm with logging or cfdump that the value of p1 is what you think it is, and isn't actually the string value "p1".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    60
    Rep Power
    5
    kiteless to the rescue again! Thanks mate, I think I'm in danger of getting the hang of this now.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    6
    As an aside, do not forget to VAR/LOCAL scope all of your function local variables. It is also a good practice to scope all variables ie "arguments.p1" instead of "p1".

    Not tested, but something along these lines


    Code:
    <cffunction name="printPO" access="remote" output="false">
        <cfargument name="p1" type="string" required="yes">
    
        <cfset VAR replyStruct = StructNew()>
        <cfset VAR poPdf = "">
    
        <cfdocument format="pdf" name="poPdf">
            <P>#arguments.p1#</P>
            <h3><U>FROM:</U></h3>
            <P>testcompany,<BR>
            4 Smith Street,<BR>
            Melbourne, Victoria,<BR>
            Australia 3000<BR>
        </cfdocument>
        <cfprint source="poPdf" printer="hp LaserJet 4300">
        <!--- "look Ma, no # signs" ---> 
        <cfset replyStruct.status = "ALLOK">
        <cfset replyStruct.param = arguments.p1>
    
        <cfreturn replyStruct>
    </cffunction>

IMN logo majestic logo threadwatch logo seochat tools logo