Skip navigation
Currently Being Moderated

CFHeader/CFContent is halting the rest of my page

Jan 30, 2012 2:01 PM

I am posting to another page form information, and then spitting out a generated document.

 

<cfheader name="content-disposition" value="filename=#rejectSearchResults.RejectTempPath#">

<cfcontent type="application/msword"><cfoutput>#documentGen#</cfoutput>

 

This code right here pops open my RTF document to the user, but instead of going to the posted page it instead stays on the same page and halts further processing. How do I make the document open up and continue processing the rest of the code?

 
Replies
  • Currently Being Moderated
    Jan 30, 2012 3:11 PM   in reply to cold_blue

    cfthread might help, but what you are describing is very strange.  What exactly is supposed to happen once the user is presented with the document?

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 30, 2012 7:04 PM   in reply to cold_blue

    That's how cfcontent works.  Maybe an iframe will give you what you want.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 2:53 AM   in reply to cold_blue

    cold_blue wrote:

     

    Well, what is happening is I have a page, index.cfm, that is basically a big form that users enter in information. Then I set the action page of that form to another .cfm file that is running stored procedures, and I'm using those queries plus the form paramaters to do a find/replace inside a RTF Word document.

     

    The thing is, as soon as they click the submit button, the generated document pops up right away (the browser never sends the user to the action page). I want the user to be able to go to the action page, where I have a table with additional documents to download.

     

    <table align="center">

       <h4>Document Created</h5>

       <cfoutput>

        <p>

         Document Downloads: [<a href="#pathToCover#">Cover Template</a>]

         [<a href="#pathToRedetermination#">Redetermination Template</a>] <br />

         Please click <a href="./index.cfm">here</a> to return to DocGen.

        </p>

       </cfoutput>

      

       <cfheader name="content-disposition" value="filename=#rejectSearchResults.RejectTempPath#">

       <cfcontent type="application/msword"><cfoutput>#documentGen#</cfoutput>

      </table>

     

    As you can see, on the page that is receiving the form paramaters, I have a table with the cfheader/cfcontent tags below. Above that is my Replace() commands, stored procedure, conitionals, etc. The user never even sees any of the HTML (they never even leave the form once they click submit, the generated document just pops up right away).

     

    From what you describe, the implementation requires one more step between the action page and the download page. Something like this:

     

    (1) form_page => (2) action_page (running stored procedures, using those queries plus the form paramaters to do a find/replace inside a RTF Word document, etc., etc.) => (3) CFM page that uses cfheader and cfcontent to generate document for download.

     

    Provide, for example, a link or button to enable the user to go from (2) to (3).

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 4:11 AM   in reply to cold_blue

    You cannot do both of those on the same page (unless you are talking about embedding). An html page can only return a single content type. So the action page can return text/html OR the rtf document, but not both. For that you would need a separate frame or window, as mentioned above.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 8:44 AM   in reply to cold_blue

    The code generating the data and the cfheader/cfcontent must be grouped together in the same script.

     

     

    Keep in mind you only need an iframe if you want to display the document in-line within the browser.

     

     

    -Leigh

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 10:36 AM   in reply to cold_blue

    shoots out the paths to additional documents ... my generated document

    Is there a reason you must do both in the same procedure? Because it sounds like it might be trying to do too much at once.

     

    If you really cannot separate them, one possibility is to write the main content to a temporary file which could be accessed from either location. Then display it with cfcontent's "file" attribute.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 31, 2012 11:22 AM   in reply to cold_blue

    cold_blue wrote:

     

    Well, the stored procedure shoots out the paths to additional documents, which I want to supplement with my generated document. So all of this is coming from the same script/cfm file. Those additional files can't be displayed for download since cfheader/cfcontent wont allow that. I really don't know how I can use an iframe to circumvent this since the stored procedure that generates the document and additional paths to files for download has to be grouped togethor in the same script.

    From what you describe, the implementation requires one more step between the action page and the download page. Something like this:

     

    (1) form_page => (2) action_page (running stored procedures, using those queries plus the form paramaters to do a find/replace inside a RTF Word document, etc., etc.) => (3) CFM page that uses cfheader and cfcontent to generate document for download.

     

    Provide, for example, a link or button to enable the user to go from (2) to (3).

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 1, 2012 12:45 AM   in reply to cold_blue

    cold_blue wrote:

     

    The problem I am experiencing with going from step 2, to step 3, is the issue of sending what cfheader/cfcontent needs.

     

    <cfheader name="content-disposition" value="filename=#rejectSearchResults.RejectTempPath#">

    <cfcontent type="application/msword"><cfoutput>#documentGen#</cfoutput>

     

    That is no problem at all. For example, you can solve the problem using a form, a database or the session scope, or a combination of all three, on the action page.

     

    1) form

    <form method="post">

    <!--- Store data as value in hidden fields (ideal for small amounts of data). Show user submit button to take him to document page--->

    </form>

     

    2) session

    <cfset session.RejectTempPath = rejectSearchResults.RejectTempPath>

    <cfset session.documentGen = documentGen>

    <!--- Add link or button to take user to document page. The data will then be available in the session scope--->

     

    3) database

    Store in the database all the values you will need to create the document page. Add a link to take the user to the document page. On the document page, start with a query to retrieve the data from the database.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2014 2:40 PM   in reply to cold_blue

    I want to create a Word doc so I am using cfcontent to create a word doc that I archive. I've left the default not to delete, but as cold_blue has explained above, CF server sends the doc to the requesting browser and no further code runs. Instead of sending the document back to the user I need to hash the saved document, enter that information into my database for later secure retrieval, and then send other html back to the requesting browser instead of the document that cfcontent rendered. I can do this operation with cfdocument format="pdf" and it works just fine: user submits to accept/commit the doc, CF server generates and stores the pdf, gets a hash of it, enters that and other info into my table_documents, returns to the requesting browser a link to the pdf and other updated html. I have not found any such analogous functionality with cfcontent.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points