2

I want to submit a form without redirecting page. Form is submitted to third party so i can't make changes in php. What I want to do is:-

  1. Submit for without visiting third party page.
  2. After successful submit show alert.

Current I am using hidden iframe and form target to hidden iframe but I am not satisfied. Is there is any better way to do this using javascript or jquery.

My Form:-

<form target="iframe" action="http://www.example.com"  type="post" id="myform">
<input type="text" value="" name="name">
<input type="submit" name="submit">
</form>

My Iframe:-

<iframe style="display:none" id="iframe"></iframe>
user3141688
  • 21
  • 1
  • 3

4 Answers4

1

You need to use Ajax for that kind of request.

Please look at some tutorials, this for example http://www.w3bees.com/2013/08/submit-form-without-page-refresh-with.html

alexanderkustov
  • 496
  • 1
  • 5
  • 16
1

Change the iframes id attribute to name:

<iframe style="display:none" name="iframe"></iframe>
pstenstrm
  • 6,339
  • 5
  • 41
  • 62
0

You can use jquery here

 <form  action="http://www.example.com" id="myform">
 <input type="text" value="" name="name">
 <input type="submit" name="submit">
 </form>

and after in jquery you write like

   // bind to the form's submit event 
    $('#myform').submit(function() { 
     alert("ok");
     return true; 
   }); 
kondapaka
  • 132
  • 1
  • 10
0

Consider using a PHP proxy.

Copy the script from here to anywhere you like on your own server.

Modify line 11 so that it points to the URL you are posting to at the moment.
// Destination URL: Where this proxy leads to.
$destinationURL = 'http://www.otherdomain.com/backend.php';

Then in your ajax script, change the URL to your proxy.php script.

Hayko Koryun
  • 1,214
  • 2
  • 12
  • 30