1

I am having a problem with an HTML form to which I just cannot find a working solution, hence this post. All I want to know is if this is possible in any way or not?

Situation: I am trying to send an HTML form to an URL from a different domain. When submitting the form, I should not get redirected. I apparently cannot use Javascript (according to the accepted answer in this post), as this would trigger a CORS Request which I cannot use because of the same-origin policy.

and there is no javascript involved in posting the form, then the same origin policy is not applicable.

Things I've tried:

  1. Submitting via Javascript
  2. Setting the target to either blank or to an invisible iframe
  3. Searched through Google and StackOverflow.

The code below works fine, it just redirects me to someotherdomain.com, which I don't want. I want to stay on the current page.

<form method="post" action="someotherdomain.com">
    // all the input fields

    <input type="submit" value="submit">
</form>

Is this possible in any way or not? Could I solve it in a way that I haven't considered yet?

EDIT: I cannot enable cross-origin requests.

  • Can you not use a `header('Location: xxxxx');` or Ajax? – Granny Jan 25 '18 at 12:26
  • I cannot use anything javascript related as this would violate the same-origin policy and the request would not fire. – Marko Maric Jan 25 '18 at 12:27
  • I am not sure what your issue is. You can certainly trigger a form to submit to another domain. You cannot do an Ajax post to another domain. You are not telling us the full story. Post some code – mplungjan Jan 25 '18 at 13:23
  • @mplungjan Yes, I certainly can submit a form to another domain, I do know that. Thing is that I don't want it to redirect me to the target URL. And as I understand it, not redirecting is only possible via javascript. And I cannot use Javascript as of the same-origin policy. – Marko Maric Jan 25 '18 at 13:36
  • You confused me with the redirect. It is not a redirect. Your question seems to be "How do I post a form to another domain without my page loading the target" - You should be able to target an iFrame - alternatively use CURL on your own server – mplungjan Jan 25 '18 at 13:40
  • Yeah, that was my bad. I tested your solution with the iframe again and it worked. I've tested it before using that method but it didn't work then. Seems like I've made some stupid mistake there. If you create an answer, I can accept it – Marko Maric Jan 25 '18 at 13:50

0 Answers0