function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesRedSalesRed 

Post Form Data & Redirect to External Site In Same Process

Hello, I have a Force.com site in which I have APEX Forms. I wish to perform the following behaviour from one of my forms.

 

- On a user entering their form data the form action will post the data to an external site and as part of this redirect to this site as per traditional html forms specified with post.

 

I know I can post to an external site via the HTTP Request object by setting the request method to post but on completing my form action unless i use a PageReference and set the page reference to my external site I'm not sure how I can complete my task.

 

I wish to perform this in one POST and not have 2 steps (one posting via the HTTPRequest object and a separate PageReference redirecting to the site). Can this be achieved?

 

Thanks in advance.

izayizay

Could't you use a method that returns a PageReference and do the HTTP request within that method. Ex.

 

public PageReference sendAndRedirect(){

     HttpRequest req = new HttpRequest();
     req.setEndpoint("url");
     req.setMethod('Post');

     ....

 

     //Send request

 

     ....

 

     if(success){

         PageReference pr = new PageReference("url")

         pr.setRedirect(true);

         return pr;

     }else{

        return null;

     }

}

 

Hope this helps!

ItruItru
Hi,
DId you achieved your task?
If so, can you please detail how?
I facing with the same issue here.
Thanks!