[html] HTML Form Redirect After Submit

This is my form code:

<form enctype="multipart/form-data" name="upload-file" method="post"  action="http://example.com/upload">
    <div class="formi">
        <input id="text-link-input" type="text" name="url" class="link_form" value="your link"  onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;"   />
        <input type="submit" value="OK" class="link_but" />
    </div>
    <div class="upl" title="Upload"><img src="http://example.com/example.png" alt="" style="vertical-align:middle;"/>Upload
        <input type="file" name="file" size="1" class="up" onchange = "document.getElementById('text-link-input').value = String(this.value).replace('C:\\fakepath\\','')"/>
    </div>
</form>

Now, I want to redirect the submitter to any page of my choice after the form data has been submitted, but the action resides on another website where I cannot edit. Is it possible to redirect the user to any page after he has submitted the data to that site?

From some Googling, this is what I have found. Adding this to form code:

onSubmit=window.location='http://google.com'

This didnt work. Maybe I didnt implement it correctly? This is what I did:

<form enctype="multipart/form-data" name="upload-file" method="post" onSubmit=window.location='http://google.com' action="http://example.com/upload">

Another person says adding a hidden field should work:

<input type="hidden" name="redirect" value="http://your.host/to/file.html"> 

How should I implement this is my code?

Suggestions and help awaited...

This question is related to html forms

The answer is


Try this Javascript (jquery) code. Its an ajax request to an external URL. Use the callback function to fire any code:

<script type="text/javascript">
$(function() {
  $('form').submit(function(){
    $.post('http://example.com/upload', function() {
      window.location = 'http://google.com';
    });
    return false;
  });
});
</script>