Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

POST copy of Form to External

Go to End

8 Posts   2583 Views


Community Member, 545 Posts

9 September 2009 at 2:28am

I have a Custom Form that I need to write to the DB as well as POST to an external service (SalesForce). How do I map a copy of the Form contents to a Standard POST function? This is probably really simple and I'm just missing something basic.


Community Member, 712 Posts

10 September 2009 at 9:23am

Edited: 10/09/2009 9:23am

Two ways:

1. Before the form is submitted, perform a javascript XHR to SalesForce. The downside is the XHR is submitted even if any server side validation fails.

2. After the form is submitted, perform a cURL (or similar) server request to SalesForce submitting the POST data.


Community Member, 244 Posts

10 September 2009 at 9:47am

Edited: 10/09/2009 9:48am

You shouldn't use JS for this kind of thing as Hamish suggested - instead just create a HTTP request using cURL or similar.

Edit: Sorry Hamish, didn't see you had already suggested that. So yeah, use the the second method Hamish suggested.


Community Member, 712 Posts

10 September 2009 at 9:49am

Edited: 10/09/2009 9:50am

Yeah, should add that another downside to 1 (using JS) is that browsers might think there is a security issue with the page, since it is trying to send data to another domain.

Bruce B

Community Member, 164 Posts

14 September 2009 at 4:54pm

I'm also trying to post some form data to an external site. In this case, its SecurePay, to process membership payments. I'm just working locally at the moment, attempting to post to another page on the same site.

Curl appears to work as claimed ie it sends off the request to the target page and returns the target page data to the originating page. However, this leaves the user on the original page. I want to send the user to the SecurePay site with all the necessary data in a POST request.

In the past, I have used a work-around which is to show the user a second form, asking them to confirm their details, then using that to send to the payment site. This time around, I'd like to avoid the need for a second form, if possible.

Is there something I've missed?


Community Member, 54 Posts

20 September 2009 at 9:24am

There is an easier way:


This causes the form to skip the normal SS routine and submit straight to a url


Community Member, 178 Posts

6 June 2010 at 3:36am

anyone have an example of using curl for this??
I have to integrate with saleforce as well...


Community Member, 545 Posts

8 June 2010 at 1:06am

This is what I'm using right now, Right now this form writes exclusively to sales force, though if you need to write to the DB as well you'd just need to create a new object and remap the fields

function doWholesale($data, $form) {
		if (!function_exists('curl_init')) {
			echo "Error: $error\n";
		// Create cURL
		$ch = curl_init();
		if (curl_error($ch) != "") {
			 echo "Error: $error\n";
		// Set URL
		curl_setopt($ch, CURLOPT_URL, '');
		curl_setopt($ch, CURLOPT_POST,  1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));