多表单提交1提交javascript半工作

时间:2012-11-01 21:36:41

标签: php javascript html mysql forms

我在1页中有两个需要提交的表格我似乎有限,因为它是由mikrotik的热点。 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>

所以我的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>

正如您所见,我试图自动提交用户名和密码 所以用户只输入他的电子邮件地址,为此我想存储电子邮件 一个数据库 与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');  

?>

发生的事情是电子邮件地址存储在mysql表中 但是存储用户名和密码的表单没有通过,我最终登录了登录页面

我错过了什么?

全部谢谢

1 个答案:

答案 0 :(得分:0)

好的答案是消除login.php中的所有javascript并使用一个简单的表单,signin.php使用pap登录通过用户名和密码。所有工作和快乐的快乐兔子