-1

I've a little problem. I submit a form to my route/uploadpdf with

<form action="http://localhost:3000/user/uploadpdf" enctype="multipart/form-data" method="post" onSubmit=window.location.replace('http://localhost:3000/statictoken')>
    <input type="file" name="upload" multiple>
    <input type="submit" value="Upload"> 
</form>

and when it is complete the browser tries to traverse to uploadpdf.

What I actually want is to stay on the current page ("statictoken") and refresh. You can see I've attempted to replace onSubmit, but it doesn't work.

WishIHadThreeGuns
  • 1,225
  • 3
  • 17
  • 37
  • Why not redirect back from `uploadpdf` to `statictoken` after processing the data? Or if possible, just do your business in `statictoken`? And just to be clear, are you using a framework or something? – Carl Binalla Sep 18 '19 at 06:13
  • Possible duplicate of https://stackoverflow.com/questions/5733808/submit-form-and-stay-on-same-page – Casper Sep 18 '19 at 06:15

1 Answers1

0

The form action attribute is used to send the request to the specified page. If you want to send the request to the current page itself, you should have the following :

<form action="/" ...>

But keep in mind that now, you have to tackle the functionality of uploadpdf page on your 'statictoken' page.

You can also redirect to the "statictoken" page from the "uploadpdf" page after the file upload completes.

Or better, you can use Ajax File Upload, so that form is submitted asynchronously without redirecting you to the "uploadpdf" page.

Prakhar Londhe
  • 1,431
  • 1
  • 12
  • 26