ADITYA PATHAK
ADITYA PATHAK

Reputation: 13

HTML: Post form from http to https

We have this code on http://soAndSo.com/path/abc.aspx page:

<form id="MainForm" name="MainForm" method="post" action="xyz.aspx">

now we need to redirect user to https://soAndSo.com/path/xyz.aspx. The problem is we can't use full URL because we need to use same code in all environments. Any idea how can we achive this using html and javascript?

Upvotes: 1

Views: 121

Answers (1)

Quentin
Quentin

Reputation: 944441

There is no way to do this in plain HTML.

With client-side JavaScript, you can document.getElementById('MainForm').action = somevalue; where somevalue is computed based on the value of location.href.

In general, you would be better off achieving this with a server side language.

However: Data entered on an HTTP page is not secure. It will be secured before transit over HTTPS, but the HTTP page containing the form could be interfered with in transit to the user (e.g. so that the submission would be sent to a different server).

You should redirect from the HTTP URI that is currently hosting the document with the <form> to a copy of that document on HTTPS.

Upvotes: 2

Related Questions