好的:我有 HTML 代码,例如:
<form method="post">
<ul>
<li>
<label for="username">Username</label>
<input type="text" id="username" size="30" onblur="checkUser()" />
<div id=user></div>
</li>
<li>
<label for="email">Email</label>
<input type="text" name="email" id="email" size="30" />
</li>
<li>
<label for="first_name">First Name</label>
<input type="text" name="first_name" id="first_name" size="30" />
</li>
<li>
<label for="last_name">Last Name</label>
<input type="text" name="last_name" id="last_name" size="30" />
</li>
<li>
<label for="cell">Cell</label>
<input type="text" name="cell" id="cell" size="30" />
</li>
<li>
<label for="street">Street</label>
<input type="text" name="street" id="street" size="30" />
</li>
<li>
<label for="city">City</label>
<input type="text" name="city" id="city" size="30" />
</li>
<li>
<label for="zip">Zip</label>
<input type="text" name="zip" id="zip" size="30" />
</li>
<li>
<label for="password">Password</label>
<input type="password" name="password" id="password" size="30" />
</li>
<li><label for="password2">Repeat Password</label>
<input type="password" name="password2" id="password2" size="30" />
</li>
<li>
<label for="submit"></label>
<button type="submit" name="submit" id="submit">Register</button>
</li>
<ul>
</form>
带有 JS 功能
function checkUser()
{
var userID=document.getElementById('username').value;
alert(userID);
createRequest();
var url= "userCheck.php?username="+userID;
//alert(url);
request.open("GET",url,true);
request.onreadystatechange=updatePage;
request.send(null);
}
我被困在document.getElementById('username').value;
. 警报说值是username
。
我正在尝试使用此函数从所述文本框中提取值并将其传递给userCheck.php
查询以查看用户名是否已被使用。
有什么帮助吗?
更新 - 代码的其余部分
<? include "heading.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
function mailer($to,$username,$hash){
$subject = "Test mail";
$message = "http://www.me.com/verify.php?username=$username&hash=$hash";
$from = "me@myself.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
if(isset($_POST['submit'])){
if($_POST['password']==$_POST['password2'] && !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['email']) && !empty($_POST['last_name'])){
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])){
$msg = 'The email you have entered is invalid, please try again.';
}else{
require_once "UserManagement.php";
$hash = md5(rand(0,1000));
$usman=new UserManagement();
$usman->createUser($_POST['username'],$_POST['email'],$_POST['first_name'],$_POST['last_name'],$_POST['cell'],$_POST['street'],$_POST['city'],$_POST['zip'],md5($_POST['password']),$hash);
mailer($_POST['email'],$_POST['username'],$hash);
$msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been send to your email.';
header('Location: http://www.me.com/me');
}
}else{
$msg = 'Form Data Incorrect';
sleep(10);
header('Location:http://www.me.com/me');
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "templatemo_menu", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
</head>
<body id="sub_page">
<div id="templatemo_wrapper">
<div id="templatemo_top">
<div id="templatemo_login">
<?include "loginbox.php"?>
</div>
</div> <!-- end of top -->
<div id="templatemo_header">
<div id="site_title"><h1><a href="http://www.spaladonna.com">SPA LaDonna</a></h1></div>
<div id="templatemo_menu" class="ddsmoothmenu">
<? include "mainmenu.php" ?>
</div> <!-- end of templatemo_menu -->
</div> <!-- end of header -->
<? include "checkuser.php"?>
<div id="templatemo_main">
<div id="templatemo_content">
<div class="col_fw">
<h1>Register User</h1>
<fieldset>
<legend>New User Signup</legend>
<form method="post">
<ul>
<li><label for="username">Username</label>
<input type="text" id="username" size="30" onblur="checkUser()" />
<div id=user > </div>
</li>
<li><label for="email">Email</label>
<input type="text" name="email" id="email" size="30" />
</li>
<li><label for="first_name">First Name</label>
<input type="text" name="first_name" id="first_name" size="30" />
</li>
<li><label for="last_name">Last Name</label>
<input type="text" name="last_name" id="last_name" size="30" />
</li>
<li><label for="cell">Cell</label>
<input type="text" name="cell" id="cell" size="30" />
</li>
<li><label for="street">Street</label>
<input type="text" name="street" id="street" size="30" />
</li>
<li><label for=city">City</label>
<input type="text" name="city" id="city" size="30" />
</li>
<li><label for="zip">Zip</label>
<input type="text" name="zip" id="zip" size="30" />
</li>
<li><label for="password">Password</label>
<input type="password" name="password" id="password" size="30" />
</li>
<li><label for="password2">Repeat Password</label>
<input type="password" name="password2" id="password2" size="30" />
</li>
<li><label for="submit"></label>
<button type="submit" name="submit" id="submit">Register</button>
</li>
<ul>
</form>
</fieldset>
<script type="text/javascript">
var request=null;
function createRequest()
{
try{
request= new XMLHttpRequest();
}catch(tryMicrosft){
try{
request= new ActiveXObject("Msxml2.XMLHTTP");
}catch(otherMicrosoft){
try{
request=new ActiveXObject("Microsoft.XMLHTTP");
}catch(failed){
request=null;
}
}
}
if(request==null)
alert("Error creating request object!");
//else alert("Successfully created");
}
function checkUser()
{
var userID=document.getElementById('username').value;
alert(userID);
createRequest();
var url= "userCheck.php?username="+userID;
//alert(url);
request.open("GET",url,true);
request.onreadystatechange=updatePage;
request.send(null);
}
function updatePage()
{
if(request.readyState==4)
replaceText('user',request.responseText);
}
function clearText(el) {
if (el != null) {
if (el.childNodes) {
for (var i = 0; i < el.childNodes.length; i++) {
var childNode = el.childNodes[i];
el.removeChild(childNode);
}
}
}
}
function replaceText(el, text) {
if (el != null) {
el=document.getElementById(el);
clearText(el);
//setTimeout("alert("HELLO")", 4000);
var newNode = document.createTextNode(text);
el.appendChild(newNode);
}
}
</script>
</div>
<div class="col_fw_last">
<div class="col_w300 float_l">
</div>
<div class="col_w300 float_r">
</div>
<div class="cleaner"></div>
</div>
</div> <!-- end of content -->
<div id="templatemo_sidebar">
<h4>Categories</h4>
<div class="sidebar_box">
<ul class="templatemo_list">
<li><a href="#">Aliquam pretium porta odio</a></li>
<li><a href="#">Integer sit amet erat sit</a></li>
<li><a href="#">Nunc elementum mollis</a></li>
<li><a href="#">Quisque dictum pharetra</a></li>
</ul>
</div>
<div class="cleaner h40"></div>
<h4>Cool Links</h4>
<div class="sidebar_box">
<ul class="templatemo_list">
<li><a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a></li>
<li><a href="http://www.flashmo.com/page/1" target="_parent">Flash XML Galleries</a></li>
<li><a href="http://www.flashmo.com" target="_parent">Flash Templates</a></li>
<li><a href="http://www.webdesignmo.com/blog" target="_parent">Web Design Resources</a></li>
</ul>
</div>
<div class="cleaner h40"></div>
<h4>Latest Updates</h4>
<div class="news_box">
<a href="#">Donec eu orci dolor</a>
<p>Pellentesque in nunc quam. Sed molestie ultricies ante, vel scelerisque diam varius sed. </p>
</div>
<div class="news_box">
<a href="#">Aliquam bibendum vulputate</a>
<p>Auris nisl mi, aliquet ac lobortis ut, tincidunt in tortor nisl vitae lectus dapibus pellentesque.</p>
</div>
<div class="news_box">
<a href="#">Nunc viverra vestibulum </a>
<p>Nunc viverra vestibulum magna, nec dignissim turpis rhoncus tincidunt. Donec ac nibh arcu. </p>
</div>
<div class="news_box">
<a href="#">Fusce placerat ultrices</a>
<p>Integer ac ultricies nisi. Curabitur velit ante, porttitor ac feugiat a, porta ut lectus.</p>
</div>
</div> <!-- end of sidebar -->
<div class="cleaner"></div>
</div> <!-- end of main -->
</div> <!-- end of wrapper -->
<div id="templatemo_footer_wrapper">
<div id="templatemo_footer">
Copyright © 2012 <a href="#"></a>
<div class="cleaner"></div>
</div>
</div>
</body>
</html>
<? ob_flush(); ?>
和 header.php
<? ob_start(); ?>
<?php
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
if(isset($_POST['login'])){
require_once "UserManagement.php";
$usman=new UserManagement();
if($usman->authenticate($_POST['username'],md5($_POST['password']))){
header('Location: http://www.me.com')
}else {
echo "Authentication error";
echo '<a href="index.php">Home</a>';
}
die();
}
?>
如果需要的话,我也可以发布所有的菜单和东西