Artem Ushakov Artem Ushakov - 1 year ago 108
PHP Question

Two actions in a single form

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="">
<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">
<input type="checkbox" name="rememberme" id="remember_me">
Remember me on this computer
<p class="submit"><input type="submit" name="commit" value="Login"></p>

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
, it does nothing (just sends me to the second login form).
But when I use
, 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
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download