13 Replies Latest reply: Mar 24, 2014 2:40 PM by gordon va RSS

    CFHeader/CFContent is halting the rest of my page

    cold_blue Community Member

      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?

        • 1. Re: CFHeader/CFContent is halting the rest of my page
          Dan Bracuk Community Member

          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?

          • 2. Re: CFHeader/CFContent is halting the rest of my page
            cold_blue Community Member

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

            • 3. Re: CFHeader/CFContent is halting the rest of my page
              Dan Bracuk Community Member

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

              • 4. Re: CFHeader/CFContent is halting the rest of my page
                BKBK MVP

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

                • 5. Re: CFHeader/CFContent is halting the rest of my page
                  -==cfSearching==- Community Member

                  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.

                  • 6. Re: CFHeader/CFContent is halting the rest of my page
                    cold_blue Community Member

                    I see, that makes sense. I guess I would have to go the iframe route, but then comes the issue of getting the storedprocedure return values to the cfheader/cfcontent, since if it's a seperate instance of the browser, I'm going to take a guess that it wont be able to read them.

                    • 7. Re: CFHeader/CFContent is halting the rest of my page
                      -==cfSearching==- Community Member

                      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

                      • 8. Re: CFHeader/CFContent is halting the rest of my page
                        cold_blue Community Member

                        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.

                        • 9. Re: CFHeader/CFContent is halting the rest of my page
                          -==cfSearching==- Community Member

                          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.

                          • 10. Re: CFHeader/CFContent is halting the rest of my page
                            BKBK MVP

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

                            • 11. Re: CFHeader/CFContent is halting the rest of my page
                              cold_blue Community Member

                              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>

                               

                              I tried having a link using this format: <a href="./download.cfm?documentGen=#documentGen#"> Download File</a> but I guess it is just way, way too big to pass via URL. I've been trying to use cfhttp to do it wont work, unless I'm doing it wrong.

                                 

                              How do I send #documentGen# to the 3rd step? For a more general view on how I am constructiing this: http://www.jensbits.com/2009/06/21/using-coldfusion-to-generate-a-word-document/ I'm modeling it after her blog post, since I couldn't really find a way to manipulate MS Word docs.

                              • 12. Re: CFHeader/CFContent is halting the rest of my page
                                BKBK MVP

                                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.

                                • 13. Re: CFHeader/CFContent is halting the rest of my page
                                  gordon va Community Member

                                  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.