昨晚有人在这里从头开始我的第一次验证帮了我很多,自昨晚以来我带了很多。这是我第一次接触JQuery,我为我的crumby编码道歉。以下是我的工作正常和花花公子验证UP直到最后一个else语句:
//VALIDATE FIRST REGISTER PAGE!
$('#submit1').live('click', function() {
check_value1();
});
function check_value1(){
var firstname = $('#firstname').val();
var lastname = $('#lastname').val();
var email = $('#email').val();
var password = $('#password').val();
var username = $('#username').val();
if(firstname =='' || firstname.length <2)
$('#fnameError').fadeIn().fadeOut(5000);
else if(lastname =='' || lastname.length <2)
$('#lnameError').fadeIn().fadeOut(5000);
else if(email =='' || email.length <5)
$('#emailError').fadeIn().fadeOut(5000);
else if(password =='' || password.length <6)
$('#passError').fadeIn().fadeOut(5000);
else if(username =='' || username.length <5)
$('#usernameError').fadeIn().fadeOut(5000);
else
{
$('#register1').fadeOut();
$('#register2').fadeIn();
}
}
//VALIDATE SECOND REGISTER PAGE
$('#submit2').live('click', function() {
check_value2();
});
function check_value2(){
var gender = $('#gender').val();
var seeking = $('#seeking').val();
var month = $('#month').val();
var day = $('#day').val();
var year = $('#year').val();
if(gender =='' || gender.length <4)
$('#genderError').fadeIn().fadeOut(5000);
else if(seeking =='' || seeking.length <4)
$('#seekingError').fadeIn().fadeOut(5000);
else if(month =='' || month.length > 2)
$('#monthError').fadeIn().fadeOut(5000);
else if(day =='' || day.length > 2)
$('#dayError').fadeIn().fadeOut(5000);
else if(year =='' || year.length > 4 || year > 1994 )
$('#yearError').fadeIn().fadeOut(5000);
else
{
$('#register2').fadeOut();
$('#register3').fadeIn();
}
}
//VALIDATE THIRD PAGE
$('#submit3').live('click', function() {
check_value3();
});
function check_value3(){
var height = $('#height').val();
var body_type = $('#body_type').val();
var ethnicity = $('#ethnicity').val();
var religion = $('#religion').val();
if(height =='' || height.length <3)
$('#heightError').fadeIn().fadeOut(5000);
else if(body_type =='' || body_type.length <4)
$('#bodyError').fadeIn().fadeOut(5000);
else if(ethnicity =='' || ethnicity.length <5)
$('#ethError').fadeIn().fadeOut(5000);
else if(religion =='' || religion.length <5)
$('#relError').fadeIn().fadeOut(5000);
else
{
$('#register3').fadeOut();
$('#register4').fadeIn();
}
}
//VALIDATE FOUTH PAGE
$('#submit4').live('click', function() {
check_value4();
});
function check_value4(){
var city = $('#city').val();
var state = $('#state').val();
var zip = $('#zip').val();
if(city =='' || city.length <2)
$('#cityError').fadeIn().fadeOut(5000);
else if(state =='' || state.length <2)
$('#stateError').fadeIn().fadeOut(5000);
else if(zip =='' || zip.length <5)
$('#zipError').fadeIn().fadeOut(5000);
else
{
var firstnameA = encodeURIComponent($('#firstname').val());
var lastnameA = encodeURIComponent($('#lastname').val());
var emailA = encodeURIComponent($('#email').val());
var passwordA = encodeURIComponent($('#password').val());
var usernameA = encodeURIComponent($('#username').val());
var genderA = encodeURIComponent($('#gender').val());
var seekingA = encodeURIComponent($('#seeking').val());
var monthA = encodeURIComponent($('#month').val());
var dayA = encodeURIComponent($('#day').val());
var yearA = encodeURIComponent($('#year').val());
var heightA = encodeURIComponent($('#height').val());
var bodytypeA = encodeURIComponent($('#body_type').val());
var ethnicityA = encodeURIComponent($('#ethnicity').val());
var religionA = encodeURIComponent($('#religion').val());
var cityA = encodeURIComponent($('#city').val());
var stateA = encodeURIComponent($('#state').val());
var zipA = encodeURIComponent($('#zip').val());
$('#register4').fadeOut(5000);
$('#loading').show();
$.ajax
({
type: "POST",
url: "../register.php",
data: {firstnameB:firstnameA, lastnameB:lastnameA, emailB:emailA, passwordB:passwordA, usernameB:usernameA, genderB:genderA, seekingB:seekingA, monthB:monthA, day:dayA, yearB:yearA, heightB:heightA, bodytypeB:bodytypeA, ethnicityB:ethnicityA, religionB:religionA, cityB:cityA, stateB:stateA, zipB:zipA },
success: function(){ $('#loading_text').delay(5000).hide(); $('#success').fadeIn();}
});
return false;
}
}
最后一个语句应该采用用户输入的值并通过AJAX将它们发送到register.php文件。我不认为我正在正确地调用该函数。注册php在没有Jquery和AJAX的情况下工作正常。供您参考,如果您需要,我将发布我的HTML的快速版本以及我的PHP解码发送变量的方式:
<input type="submit" value="Register" id="submit4"/>
这是应该激活最后一个功能的最后一个提交按钮。
这是我的php的开头以及它如何解码正在发送的变量
$email_a = htmlspecialchars(trim(urldecode($_POST['emailB'])));
$user_name_a = htmlspecialchars(trim(urldecode($_POST['usernameB'])));
$pwd_unencrypted_a = htmlspecialchars(trim(urldecode($_POST['passwordB'])));
$first_name_a = htmlspecialchars(trim(urldecode($_POST['firstnameB'])));
$last_name_a = htmlspecialchars(trim(urldecode($_POST['lastnameB'])));
$month = htmlspecialchars(trim(urldecode($_POST['monthB'])));
$day = htmlspecialchars(trim(urldecode($_POST['dayB'])));
$year = htmlspecialchars(trim(urldecode($_POST['yearB'])));
$city_a = htmlspecialchars(trim(urldecode($_POST['cityB'])));
$state_a = htmlspecialchars(trim(urldecode($_POST['stateB'])));
$zip_a = htmlspecialchars(trim(urldecode($_POST['zipB'])));
$gender_a = htmlspecialchars(trim(urldecode($_POST['genderB'])));
$gender_of_interest_a = htmlspecialchars(trim(urldecode($_POST['seekingB'])));
$height_cm_a = htmlspecialchars(trim(urldecode($_POST['heightB'])));
$body_type_a = htmlspecialchars(trim(urldecode($_POST['bodytypeB'])));
$ethnicity_a = htmlspecialchars(trim(urldecode($_POST['ethnicityB'])));
$religion_a = htmlspecialchars(trim(urldecode($_POST['religionB'])));
$email = strip_tags($email_a);
$user_name = strip_tags($user_name_a);
$pwd_unencrypted = strip_tags($pwd_unencrypted_a);
$first_name = strip_tags($first_name_a);
$last_name = strip_tags($last_name_a);
$city = strip_tags($city_a);
$state = strip_tags($state_a);
$zip = strip_tags($zip_a);
$gender = strip_tags($gender_a);
$gender_of_interest = strip_tags($gender_of_interest_a);
$height_cm = strip_tags($height_cm_a);
$body_type = strip_tags($body_type_a);
$ethnicity = strip_tags($ethnicity_a);
$religion = strip_tags($religion_a);
$edu = strip_tags($edu_a);
$pwd = md5($pwd_unencrypted);
$full_name = $first_name . " " . $last_name;
$pwd_for_email = $pwd_unencrypted;
$this_day = date(j);
$this_month = date(m);
$this_year = date(Y);
$find_height_ft = mysql_query("SELECT * FROM height WHERE CM = '$height_cm'");
while($find_height = mysql_fetch_array($find_height_ft))
{
$height_ft_a = $find_height['feet_inches'];
}
$height_ft = mysql_real_escape_string($height_ft_a);
$find_zodiac = mysql_query("SELECT * FROM zodiac WHERE Month_Z = '$month' AND Day_Z = '$day'");
while($find_zodiac_array = mysql_fetch_array($find_zodiac))
{
$zodiac = $find_zodiac_array['Sign_Z'];
}
if($this_month > $month)
{
$age = $this_year - $year;
}
elseif($this_month <= $month && $this_day < $day)
{
$age = $this_year - $year - 1;
}
else
{
$age = $this_year - $year;
}
if($age >= 18)
{
//I EDITED THIS OUT TO SAVE YOU GUYS THE TIME OF READING IT basically if all above checks out that you're 18, it will insert the variables into the DB this works fine here.
}
所以我不确定这是我编码/解码变量的方式还是我调用最后一个函数的方式。我很抱歉我的代码笨重而且像垃圾一样写。
你们过去总是帮助我一帮!我非常感谢任何提供的帮助。 -Mike
答案 0 :(得分:2)
不是将每个值分配给单独的变量,而是可以使用jQuery函数将其全部发送出去,如下所示:
$('#register4').fadeOut(5000);
$('#loading').show();
$.ajax({
type: "POST",
url: "../register.php",
data: $('#form').serialize(),
success: function(){ $('#loading_text').delay(5000).hide(); $('#success').fadeIn();}
});
注意我使用$('#form').serialize()
,确保选择所有输入所在的表单,然后它将获取输入值并以编码形式提交它们,这样您就不必单独编码每个输入值