无刷新注册代码,带验证
无刷新注册代码,带验证,本例没有判断帐号是否已经存在,如果需要可以参考《ajax用户注册验证 验证合格才能提交表单》
演示
php code
<?php
if($_post)
{
$name = $_post['name'];
$email = $_post['email'];
$username = $_post['username'];
$password = $_post['password'];
$gender = $_post['gender'];
// full name
if (eregi('^[a-za-z0-9 ]{3,20}$',$name))
{
$valid_name=$name;
}
else
{
$error_name='enter valid name.';
}
if (eregi('^[a-za-z0-9._-]+@[a-za-z0-9._-]+\.([a-za-z]{2,4})$', $email))
{
$valid_email=$email;
}
else
{
$error_email='enter valid email.';
}
// usename min 2 char max 20 char
if (eregi('^[a-za-z0-9_]{3,20}$',$username))
{
$valid_username=$username;
}
else
{ $error_username='enter valid username min 3 chars.'; }
// password min 6 char max 20 char
if (eregi('^[a-za-z0-9!@#$%^&*()_]{6,20}$',$password))
{
$valid_password=$password;
}
else
{
$error_password='enter valid password min 6 chars.';
}
// gender
if ($gender==0)
{
$error_gender='select gender';
}
else
{
$valid_gender=$gender;
}
if((strlen($valid_name)>0)&&(strlen($valid_email)>0)&&(strlen($valid_username)>0)&&(strlen($valid_password)>0) && $valid_gender>0 )
{
//mysql_query(' sql insert statement');
header("location: thanks.html");
}
else
{
}
}
?>
css code
<style type="text/css">
.err
{
font-size:11px;
padding-left:10px;
color:#cc0000;
float:left;
}
input
{
float:left;
}
</style>
xml/html code
<form autocomplete="off"
enctype="multipart/form-data" method="post" action="" name="form">
<ul>
<li id="foli1" class=" ">
<label class="desc" id="title1" for="field1">
full name </label>
<p>
<input id="name" name="name" type="text" class="field text medium" value="<?php echo $valid_name; ?>" maxlength="255" tabindex="1" /><span class="err"> <?php echo $error_name; ?></span>
</p>
</li>
<li id="foli2" class=" ">
<label class="desc" id="title2" for="field2">
email </label>
<p>
<input id="email" name="email" type="text" class="field text medium" value="<?php echo $valid_email; ?>" maxlength="255" tabindex="2" /><span class="err"> <?php echo $error_email; ?></span>
</p>
</li>
<li id="foli3" class=" ">
<label class="desc" id="title3" for="field3">
user-id </label>
<p>
<input id="username" name="username" type="text" class="field text medium" value="<?php echo $valid_username; ?>" maxlength="255" tabindex="3" /><span class="err"> <?php echo $error_username; ?></span>
</p>
</li>
<li id="foli4" class=" ">
<label class="desc" id="title4" for="field4">
password </label>
<p>
<input id="password" name="password" type="password" class="field text medium" value="<?php echo $valid_password; ?>" maxlength="255" tabindex="4" /><span class="err"> <?php echo $error_password; ?></span>
</p>
</li>
<li id="foli6" class=" ">
<label class="desc" id="title6" for="field6">
gender </label>
<p>
<select id="gender" name="gender" class="field select medium" tabindex="5" style="float:left">
<option value="0">gender</option><option value="1">male</option><option value="2">female</option>
</select><span class="err"> <?php echo $error_gender; ?></span>
</p>
</li>
<li id="foli15" class=" "></li>
<li class="buttons">
<input type="submit" value="submit" style=" background:#0060a1; color:#ffffff; font-size:14px; border:1px solid #0060a1"/>
</li>
</ul>
</form>