简体   繁体   English

多种形式提交1提交javascript正常工作

[英]Multiple form submission 1 submit javascript half working

I have 2 forms in 1 page that need submitting i seem to be limited because it is for a hotspot by mikrotik. 我在1页中有2个表单需要提交,我似乎受到限制,因为它是mikrotik的热点。 The login.html in mikrotic router is mikrotic路由器中的login.html是

<html>
<head><title>...</title></head>
<body>
$(if chap-id)
<noscript>
<center><b>JavaScript required. Enable JavaScript to continue.</b></center>
</noscript>
$(endif)
<center>If you are not redirected in a few seconds, click 'continue' below<br>
<form name="redirect" action="http://domain.name/login.php" method="post">
<input type="hidden" name="mac" value="$(mac)">
<input type="hidden" name="ip" value="$(ip)">
<input type="hidden" name="username" value="$(username)">
<input type="hidden" name="link-login" value="$(link-login)">
<input type="hidden" name="link-orig" value="$(link-orig)">
<input type="hidden" name="error" value="$(error)">
<input type="hidden" name="chap-id" value="$(chap-id)">
<input type="hidden" name="chap-challenge" value="$(chap-challenge)">
<input type="hidden" name="link-login-only" value="$(link-login-only)">
<input type="hidden" name="link-orig-esc" value="$(link-orig-esc)">
<input type="hidden" name="mac-esc" value="$(mac-esc)">
<input type="submit" value="continue">
</form>
<script language="JavaScript">
<!--
document.redirect.submit();
//-->
</script></center>
</body>
</html>

so then my login.php is this 所以我的login.php是这个

<?php
   $mac=$_POST['mac'];
   $ip=$_POST['ip'];
   $username=$_POST['username'];
   $linklogin=$_POST['link-login'];
   $linkorig=$_POST['link-orig'];
   $error=$_POST['error'];
   $chapid=$_POST['chap-id'];
   $chapchallenge=$_POST['chap-challenge'];
   $linkloginonly=$_POST['link-login-only'];
   $linkorigesc=$_POST['link-orig-esc'];
   $macesc=$_POST['mac-esc'];   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>mikrotik hotspot > login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<style type="text/css">
body {color: #737373; font-size: 10px; font-family: verdana;}

textarea,input,select {
background-color: #FDFBFB;
border: 1px solid #BBBBBB;
padding: 2px;
margin: 1px;
font-size: 14px;
color: #808080;
}
 a, a:link, a:visited, a:active { color: #AAAAAA; text-decoration: none; font-size:   
 10px; }
a:hover { border-bottom: 1px dotted #c1c1c1; color: #AAAAAA; }
img {border: none;}
td { font-size: 14px; color: #7A7A7A; }
</style>
<script language="JavaScript">
  function fnSubmit (){
     var form1Content = document.getElementById("form1").innerHTML;
     var form2Content = document.getElementById("form2").innerHTML;
 var form3Content = document.getElementById("form3").innerHTML;
     document.getElementById("toSubmit").innerHTML=form1Content+form2Content;
             document.forms.toSubmit.submit();
  }
  </script>
</head>

<body>
<!-- $(if chap-id) -->

    <form name="sendin" action="<?php echo $linkloginonly; ?>" method="post"          id="form1">
    <input type="hidden" name="username" />
    <input type="hidden" name="password" />
    <input type="hidden" name="dst" value="<?php echo $linkorig; ?>" />
    <input type="hidden" name="popup" value="true" />
</form>

<script type="text/javascript" src="./md5.js"></script>
<script type="text/javascript">
<!--
    function doLogin() {
            <?php if(strlen($chapid) < 1) echo "return true;\n"; ?>
    document.sendin.username.value = document.login.username.value;
    document.sendin.password.value = hexMD5('<?php echo $chapid; ?>' +         document.login.password.value + '<?php echo $chapchallenge; ?>');
    document.sendin.submit();
    return false;
    }
//-->
</script>
    <!-- $(endif) -->
     <div align="center">
    <a href="<?php echo $linkloginonly; ?>?target=lv&dst=<?php echo $linkorigesc; ?>">Hotspot</a>
 </div>
   <table width="100%" style="margin-top: 10%;">
<tr>
<td align="center" valign="middle">
Please log on to use the mikrotik hotspot service
    </div><br />
    <table width="240" height="240" style="border: 1px solid #cccccc; padding: 0px;"     cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="bottom" height="175" colspan="2">
    <!-- removed $(if chap-id) $(endif)  around OnSubmit -->
    <form method="POST" action="signin.php" id="form2">
   First Name<p><input type="text" name="firstname" size="30"></p>
    Surname<p><input type="text" name="lastname" size="30"></p>
Email address <font color="red"> (required)</font><p><input type="text"  name="email" size="30"></p>
    <input type="submit" value="submit" onclick="javascript:fnSubmit();"/>
 </form>
  <form name="login" id="form3 action="<?php echo $linkloginonly; ?>" method="post" onSubmit="return doLogin()" >
        <input type="hidden" name="dst" value="<?php echo $linkorig; ?>" />
        <input type="hidden" name="popup" value="true" />   
        <table width="100" style="background-color: #ffffff">
            <tr><td align="right"></td>
            <td><input type="hidden" style="width: 80px" name="username" type="text" value="user2"/></td>
            </tr>
            <tr><td align="right"></td>
            <td><input type="hidden" style="width: 80px" name="password" type="password" value="user2"/></td>
            </tr>
            <tr><td> </td>
            <td><td></td></td></td>
            </tr>
        </table>
    </form>

    </td>
    </tr>
</table>

<!-- $(if error) -->
<br /><div style="color: #FF8080; font-size: 9px"><?php echo $error; ?></div>
<!-- $(endif) -->

</td>
</tr>
</table>

<script type="text/javascript">
<!--
  document.login.username.focus();
//-->

</script>

</body>
</html>

as you can see im trying to auto submit the username and password so that the user only inputs his email address, to do this i want to store the email in a database with signin.php which is this 如您所见,即时通讯试图自动提交用户名和密码,以便用户仅输入他的电子邮件地址,为此,我想将电子邮件存储在具有signin.php的数据库中

<?php
ini_set('display_errors', 'On');
 // Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$firstname = addslashes($_POST['firstname']);
@$lastname = addslashes($_POST['lastname']);
@$email = addslashes($_POST['email']);
@$date = addslashes($_POST['date']);


// Validation
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid    email</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}


            /* adding user information to the userinfo table */
                        @$pfw_strQuery = "INSERT INTO userinfo (firstname, lastname, email, creationdate) values ".
                "('$firstname', '$lastname', '$email', NOW())";


@$pfw_host = "localhost";
@$pfw_user = "dbusername";
@$pfw_pw = "dbpassword";
@$pfw_db = "database";

$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
 die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
 die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

header('Location: http://www.google.co.uk');  

?>

what happens is that the email address is stored in the mysql table but the form which stores the username and password, does not pass through, and i end up at the login page 发生的情况是该电子邮件地址存储在mysql表中,但是存储用户名和密码的表单没有通过,我最终进入了登录页面

what am i missing? 我想念什么?

Thanks all 谢谢大家

Ok the answer was to eliminate all the javascript in login.php and use a simple form with the signin.php passing through the username and password using pap login. 确定的答案是消除login.php中的所有javascript,并使用一个简单的形式,使用pap登录通过signin.php传递用户名和密码。 All working and happy a happy bunny 所有工作和快乐的兔子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM