views:

603

answers:

4

I have to have a page submit to an external website. Not a problem.

Problem is the external website displays a successful message, not good, I need to get the site it was submitted from to be redirected to something more user friendly. The external website won't redirect, which I think might be the easiest, if I pass it a redirectto page.

Anyway, any suggestions for the easiest and less effort approach to this? I read about having an iFRAME. Is there another way?

Thanks in advance!

These are static HTML pages.

+1  A: 

I'm assuming you can't touch the markup of the external site.

If they're static you're short of solutions. I've often used the cURL library to provide this sort of functionality (posting to the external site behind the scenes).

You might be able to do it with an iframe and JavaScript. Set the target of your form to the name of the iframe (maybe hide the iframe using CSS). Then, it should submit fine.

alex
A: 

If js exists, submit via ajax (easiest to pick your library mootools, jsquery, etc), parse the http AJAX response, and code the js logic as required based on ajax response, and data returned. If no js is found, submit as a 'static' html form.

anemes
Since it is an external site which the author has no control over, any Ajax approach will run into the same origin policy and fail.
David Dorward
A: 

The IFRAME solution seems to be the simplest but, should an error occur, you might not notice.

If the site that is being submitted to returns predictable markup, then the AJAX route would be preferable, as it allows your site to parse, and react to, the results of the post. It is, however, vulnerable to the user having JavaScript disabled.

Probably the best solution, is to write your markup to use the IFRAME technique, but put an 'onsubmit' handler onto the form. If JavaScript is enabled, then the handler can do the AJAX stuff - other wise the IFRAME solution will kick in.

Just remember to add 'return false' to the onsubmit attribute, to prevent the IFRAME submission, when JavaScript is enabled.

<form action="http://external.server/submission.html" 
      target="id_of_your_IFRAME" 
      onsubmit="submitViaAJAX(); return false">
    ... form fields ...
</form>
belugabob
Since it is an external site which the author has no control over, any Ajax approach will run into the same origin policy and fail.
David Dorward
Not necessarily - jquery is perfectly capable of placing the returned markup into a DOM which can be interpreted for the decision making process.
belugabob
A: 

Since you say "the external site won't redirect", I'm assuming that you have no control over it.

This means that you have three possible approaches that I can think of.

  1. Proxy the request via your own server. This is the safe option, but won't use any cookies the third party site expects from the user.
  2. Use an iframe and assume it will never fail (because you can't read the result). It might error or time out without you being able to compensate.
  3. Use a Java Applet (or similar), and have the user accept a series of scary security warnings (if they even have the Java plug-in installed)
David Dorward