Question

I would like to say that I've already read all the similar questions, but did not find the answer I need.

So, I have the HTML form on the remote host that consists of username, password and "rememberMe" checkbox:

<form method="POST" action="http://1.2.3.4:5000/webman/login.cgi">
    <p><input type="text" name="username" value="" placeholder="Username or Email"></p>
    <p><input type="password" name="passwd" value="" placeholder="Password"></p>
    <p class="remember_me">
      <label>
        <input type="checkbox" name="rememberme" id="remember_me">
        Remember me on this computer
      </label>
    </p>
    <p class="submit"><input type="submit" name="commit" value="Login"></p>
  </form>

All I want to do is to submit data from one form to another one (another one - this is my Synology NAS Login form). But the problem is that if I write action="http://1.2.3.4:5000/webman/index.cgi", it does nothing (just sends me to the second login form). But when I use action="http://1.2.3.4:5000/webman/login.cgi", it forwards me to the login.cgi page where only the following is displayed (with correct username & passwd)

{ "result" : "success", "success" : true }

BUT: if I change login.cgi to index.cgi in the browser, I go then to my desktop as I were logged in successfully via the default form.

So, on this basis, the question is: How to send data to login.cgi, but redirect the user to .../index.cgi?

Was it helpful?

Solution

You need two forms. You can not have form in form. You need to copy data between forms with javascript. You can do that with this:

function copydata() {
    document.form1.username.value = document.form2.username.value;
    document.form1.passwd.value = document.form2.password.value;
    return 1;
}

If I am getting this right you have login with two different actions. All you have to do is to apply this code once when secondary (submit for second form) submit button is clicked.

OTHER TIPS

In the <form method="POST" action="http://1.2.3.4:5000/webman/login.cgi"> you need to add target="login_iframe" above to add the line <iframe id="login_iframe" name="login_iframe" width="0" height="0" frameborder="0" style="display: none;" ></iframe>.

Here is a script for redirecting the user after the verification. Notice that the script is only half working because there are no conditions "if the password is not correct then it should pop the inscription"

<script>
    $(document).ready(function(){
        $("#login_iframe").on("load", function(){
            location.href = "https://the address of the page/";
        });
    })
    </script>

You should change the redirection address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top