I am using jQuery to validate all of the fields on my Sign up form. Unfortunately the AJAX script at the end is not posting to the PHP file like I intended, also it is not making the necessary changes to the document as specified. When I click on submit, it clears out the error labels like it should, but seems to do nothing else.
Also, all of the error checking statements are working fine. Any ideas?
$(".button").click(function() {
// validate and process form
// first hide any error messages
$('.error').hide();
// Check if First Name is Blank
var firstname = $("input#firstname").val();
if (firstname == "") {
$("label#firstname_error").show();
$("input#firstname").focus();
return false;
}
// Check if Last Name is Blank
var lastname = $("input#lastname").val();
if (lastname == "") {
$("label#lastname_error").show();
$("input#lastname").focus();
return false;
}
// Check if Address is Blank
var address = $("input#address").val();
if (address == "") {
$("label#address_error").show();
$("input#address").focus();
return false;
}
// Check if City is Blank
var city = $("input#city").val();
if (city == "") {
$("label#city_error").show();
$("input#city").focus();
return false;
}
// Check if State is Blank
var state = $("select#state").val();
if (state == "") {
$("label#state_error").show();
$("select#state").focus();
return false;
}
// Check if ZIP Code is Blank
var zipcode = $("input#zipcode").val();
if (zipcode == "") {
$("label#zipcode_error").show();
$("input#zipcode").focus();
return false;
}
// Check if Phone Number is Blank
var phonenumber = $("input#phonenumber").val();
if (phonenumber == "") {
$("label#phonenumber_error").show();
$("input#phonenumber").focus();
return false;
}
// Check if Username is Blank
var username = $("input#username").val();
if (username == "") {
$("label#username_error").show();
$("input#username").focus();
return false;
}
// Check if Password is Blank
var password = $("input#password").val();
if (password == "") {
$("label#password_error").show();
$("input#password").focus();
return false;
}
// Check if Confirm Password is Blank
var confirmpassword = $("input#confirmpassword").val();
if (confirmpassword == "") {
$("label#confirmpassword_error").show();
$("input#confirmpasword").focus();
return false;
}
// Check if Passwords Match
if (password != confirmpassword) {
$("label#notmatching_error").show();
$("input#password").focus();
return false;
}
// Check if user picked valid username
var restrict = $("input#restrict").val();
if (restrict == "true") {
$("label#validuser_error").show();
$("input#username").focus();
return false;
}
var plan = $("select#plan").val();
var dataString = 'firstname='+ firstname +
'&lastname=' + lastname +
'&address=' + address +
'&city=' + city +
'&state=' + state +
'&zipcode=' + zipcode +
'&phonenumber=' + phonenumber +
'&username=' + username +
'&password=' + password +
'&plan=' + plan;
//alert(dataString); return false;
$.ajax({
type: "POST",
url: "../register_user.php",
data: dataString,
success: function() {
$('#buy_form').html("<div id='message'></div>");
$('#message').html("<b>Customer Information Logged</b>")
.append("Hello!")
.hide()
.fadeIn(1500, function() {
$('#message');
});
}
});
return false;
});
});
EDIT
I entirely revamped the code to break it down and now it is running the PHP script but the variables are not being posted, even when entered manually.
var dataString = 'firstname='+ firstname +
'&lastname=' + lastname +
'&address=' + address +
'&city=' + city +
'&state=' + state +
'&zipcode=' + zipcode +
'&phonenumber=' + phonenumber +
'&username=' + username +
'&password=' + password +
'&plan=' + plan;
$.ajax({
type: "POST",
url: "register_user.php",
data: dataString,
success: function(){
alert( "Hello " );
}
});
thank you for all your help so far, almost there.
Edit2
Turns out when i change success to error it returns to me, so that means there is an http error. what does this mean? the page is there becasue it is successfully posting to the database but the information is not going through?