I have issue with ajax registration form. I've tried many options but I cannot find where I made a mistake. The problem is with email. Ajax cannot read if email exist (check-email.php
). Everything else works. I used test@ok.com
to test it.
table `users`
| id | email |
| 1 | test@ok.com |
HTML
<script src="https://static.zrcdn.net/js/fw/jquery/1.7.2/jquery-1.7.2.min.js"></script>
<script>
function checkStepOne() {
jQuery("#owner_email").parents("li").find("label.error").hide();
jQuery("#owner_password").parents("li").find("label.error").hide();
jQuery("#owner_email").parents("li").find("span.check-1-r").removeClass('chkValid');
jQuery("#owner_password").parents("li").find("span.check-2-r").removeClass('chkValid');
var owner_email = jQuery("#owner_email").val();
var owner_password = jQuery("#owner_password").val();
var chkemail = 1;
var chkpass = 1;
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
$.ajax({
type: "POST",
url: "check-email.php",
data: {
owner_email,
},
success: function(responseEmail) {
if (responseEmail == 0) {
jQuery("#owner_email").parents("li").find("#e_exist").show();
chkemail = 0;
} else {
chkemail = 1;
}
}
});
if (owner_email == "" || reg.test(owner_email) == false) {
chkemail = 0;
}
if (chkemail == 1) {
jQuery("#owner_email").parents("li").find("span.check-1-r").addClass('chkValid');
} else {
jQuery("#owner_email").parents("li").find("#e_avaib").show();
}
if (owner_password.length < 5 || owner_password == "") {
chkpass = 0;
}
if (chkpass == 1) {
jQuery("#owner_password").parents("li").find("span.check-2-r").addClass('chkValid');
} else {
jQuery("#owner_password").parents("li").find("label.error").show();
}
if (chkpass == 1 && chkemail == 1) {
jQuery(".step-1").hide();
jQuery(".step-2").addClass('chkValid').show();
}
return false;
}
</script>
<form method="post" id="frmEmailSignup" onsubmit="return submitResform();">
<ul>
<li>
<label class="side-label" for="owner[email]">Email</label>
<input type="email" class="email required" id="owner_email" name="owner[email]" placeholder="Email" tabindex="0" onkeyup="return forceLower(this);" style="margin-bottom: 6px;"/>
<label class="error" id="e_exist" style="margin-top: -9px;">Email exist.</label>
<label class="error" id="e_avaib" style="margin-top: -9px;">Wrong email.</label>
<span class="check-1-r"></span>
</li>
<li class="password-row">
<label class="side-label" for="owner[password]">Password</label>
<input type="password" class="password required" id="owner_password" name="owner[password]" placeholder="Password" tabindex="0"/>
<label class="error">Wrong password.</label>
<span class="check-2-r"></span>
</li>
<li class="full">
<button type="button" class="button cta btn-disabled next next-one" tabindex="0" data-plan="register" onclick="checkStepOne();">Sign up</button>
</li>
</ul>
</form>
check-email.php
<?php
$email = $_POST['owner[email]'];
$query = mysql_query("SELECT email FROM users WHERE email = '$email'");
if (mysql_num_rows($query) == 1) {
echo '0';
} else {
echo '1';
}
?>