1

We have a form that site users can fill out on our site. The form submits to and is processed by another site. However, I'd like to show a simple confirmation page from our own site when the user submits the form.

Unfortunately, I don't have access to the remote site's code and can't specify a local confirmation page.

Here's what the flow looks like:

1) User fills out the form on our site and clicks submit.

2) The form info is sent to the remote site

3) A simple "Thank You" page is displayed on our site to the user. It does not need to display or confirm any of the submitted data.

I've thought of creating and submitting to a php script that would simply pass the query string to the remote site, then display our local "Thank You" page. I suspect this is probably simple, but I'm a php newbie and don't know how to do it.

Does anyone know if this is possible? What would the code be to accomplish something like this? Or is there a better way that I've missed?

I'm completely stuck, and appreciate any help you can offer.

  • 1
    Does the remote site give you any feedback after submitting? – srquinn Feb 25 '14 at 18:02
  • How about using [Ajax](https://api.jquery.com/jQuery.ajax/)? – Styphon Feb 25 '14 at 18:07
  • The form does display its own confirmation screen, but it's branded for the remote site. That's why we want to use our own confirmation page (so it doesn't confuse the user). We don't need any info returned from the remote site. – user3348435 Feb 25 '14 at 18:10

2 Answers2

0

Since you don't have a control over the remote site nor you can control it's output. This indicates that you can not choose where to redirect the request after the from is being submitted, therefore redirect your form to the remote site would not be a solution. (unless the remote site have a call back mechanism where you can set to which url to redirect back after submitting a form e.g. paypal)

Therefore you can send the the data to the remote site using AJAX (what is ajax) without having the user redirected to anywhere, and once that AJAX request is submitted, you can view a thank you message to the user. But, you cannot know whether the remote site have successfully received the form or not (unless they output a certain text or message!)

So one way would be to use AJAX, here's a sample of AJAX with JQuery.

 //Using JSONP if the remote site supports it
$.ajax({
  dataType: 'jsonp',
  data: 'id=10',
  jsonp: 'jsonp_callback',//false? 
  url: 'http://www.google.com'
}).always(function () {alert("Thank you ... ");} );

If the remote domain supports JSONP you could directly send the request to it but it is only limited to GET requests.

If you run that code right now from your browser console you will get the message. But that doesn't guarantee the remote site has received it, that's why the message is in the always function, not in the done or success because it will return the whole remote site page.

Please note that it's a security issue to send ajax request to a site different than the sender, therefore you can try using different approach like this which means sending the data to your site, then use some php to extract the data and pass it to the remote site.

Community
  • 1
  • 1
Mohammed Joraid
  • 6,202
  • 2
  • 27
  • 38
0

I think you have to use Curl,see my sample example

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.w3schools.com/PHP/welcome.php' );

curl_setopt($ch, CURLOPT_POST, TRUE);//Instruct cURL to do a regular HTTP POST

//Specify the data which is to be posted
$post_data['name'] = 'xyz';
$post_data['email'] = 'value';

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);


curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);// Tell curl_exec to return the response output as a string

// Execute the cURL session

$response = curl_exec($ch );

// Close cURL session and file

curl_close($ch );

echo $response; 
?>
ɹɐqʞɐ zoɹǝɟ
  • 4,342
  • 3
  • 22
  • 35