OsomA
OsomA

Reputation: 147

JS redirecting url changed

I have an input which on submit is redirecting to another page and i want this page to redirect to another using form input:

<form id="composeLink" method="post" name="composeLink" action="{$address}/" >
<input type="hidden" name="username" value="{$fields['username']}" />
<input type="hidden" name="password" value="{$fields['password']}" />
<input type="hidden" name="login" value="1" />
</form>
<script type="text/javascript">
//document.form.action = document.form.action.replace("http","https");
document.getElementById('composeLink').submit();
 </script>

Action method of this form is send using smarty. The problem is that the link is not correct. Eg: current link is http://test.com and form action is http://action.com and the redirecting page has the link combined.

LE: the action form is send correctly

What can be the problem?

Upvotes: 1

Views: 63

Answers (1)

Cem Demir
Cem Demir

Reputation: 142

Problem is on your template engine, there is no problem, i mean on html. But you can write a javascript and solve that problem. If your action generated like that ( test.com/http://action.com ), please write this one :

<script type="text/javascript">
   var newAction = document.getElementById("composeLink").action.split("http://");
   document.getElementById("composeLink").action = "http://" + newAction[1];
   document.getElementById('composeLink').submit();
</script>

If your action generated like that ( http://test.com/http://action.com ), please write this one :

<script type="text/javascript">
   var newAction = document.getElementById("composeLink").action.split("http://");
   document.getElementById("composeLink").action = "http://" + newAction[2];
   document.getElementById('composeLink').submit();
</script>

The different is your generated URL, if there is two "http" on your URL (For split), you have to use last code as i wrote

Upvotes: 1

Related Questions