4 Replies Latest reply on Jun 26, 2006 9:32 AM by leesiulung

    Redirect with POST in code

    leesiulung
      Is there a way to do a redirect with a POST to a page with code? As if you triggered it with pushing the submit button, but just in code.

      I tried cfhttp, but that only does the POST and returns a value. cflocation does not POST...

      btw, what reprecussion does it have for the person that I choose the "right answer" for?
        • 1. Re: Redirect with POST in code
          Mr Black Level 1
          Redirection with POST method is not possible by HTTP specification. If you need to pass parameters, attach them to URL, if you can. Otherwise, the processing logic has to be changed.
          • 2. Re: Redirect with POST in code
            leesiulung Level 1
            That is odd. If I can do that within the <form action="file.cfm> tag and have a submit button that user can press redirect to file.cfm with a POST, why can't I do taht in code?

            It just seems like I should be able too.
            • 3. Re: Redirect with POST in code
              Level 7
              leesiulung wrote:
              > That is odd. If I can do that within the <form action="file.cfm> tag and have a
              > submit button that user can press redirect to file.cfm with a POST, why can't I
              > do taht in code?
              >
              > It just seems like I should be able too.
              >

              Depends on what you are really trying to do, and what you are willing to
              live with as side affects.

              But I have in the past created a page that created a form and then with
              javascript submitted the form. It worked, but was probably not the best
              performance.

              <form name="theForm" action="foobar.cfm" method="post" ...>
              <input type="hidden" name="aName" value="#aValue#">
              </form>

              <script>
              document.forms["theForm"].submit();
              </script>

              But if we had a clear idea of what requirement you are filling, we maybe
              able to give you better alternatives.
              • 4. Re: Redirect with POST in code
                leesiulung Level 1
                Well, the idea is that I should post all the information to the same page for validation and then redirect it to another page with the same information posted. Although most people would use session or cookies, I prefer not too if I can avoid it.

                If I posted the information to the next page I have a problem. If there is an error next page and there is a problem I have to re-direct back to the previous page again (with a POST), but then I'm running into the same problem. I do not want to toggle the screen with two different possible views of same page (i.e. <cfif error> then display this <cfelse> display this </cfif>)

                The bottom line is with a manual post and redirect I can navigate around my site anyway I want without what I consider little hacks.

                Ian Skinner, your solution is a great idea however if the user turns of javascript it won't work. Thanks for the suggestion though!