<script>
$(function(){
$("#register_form").validate({
rules: {
username:{
required: true,
},
email:{
required: true,
email: true,
"remote":
{
url: "<?=base_url()?>Register/check_email",
type: "post",
data:
{
email: function()
{
return $('#register_form :input[name="email"]').val();
}
}
}
//remote: "<?=base_url()?>Register/check_email"
},
mobile:{
required: true,
minlength:9,
maxlength:10,
},
password:{
required: true,
},
cnfpassword:{
equalTo: "#password"
},
agree:{
required: true,
}
},messages:{
agree:{
required:'',
},
email:{
remote : jQuery.validator.format("{0} is already taken.")
}
},submitHandler: function(form) { form.submit(); }
});
});
</script>
PHP script
$(function(){
$("#register_form").validate({
rules: {
username:{
required: true,
},
email:{
required: true,
email: true,
"remote":
{
url: "<?=base_url()?>Register/check_email",
type: "post",
data:
{
email: function()
{
return $('#register_form :input[name="email"]').val();
}
}
}
//remote: "<?=base_url()?>Register/check_email"
},
mobile:{
required: true,
minlength:9,
maxlength:10,
},
password:{
required: true,
},
cnfpassword:{
equalTo: "#password"
},
agree:{
required: true,
}
},messages:{
agree:{
required:'',
},
email:{
remote : jQuery.validator.format("{0} is already taken.")
}
},submitHandler: function(form) { form.submit(); }
});
});
</script>
PHP script
< ?php /* check if email is already registered */
//connect to db using mysqli
if (!empty($_POST['email'])) {
$email = $mysqli->real_escape_string($_POST['email']);
$query = "SELECT ID FROM users WHERE user_email = '{$email}' LIMIT 1;";
$results = $mysqli->query($query);
if($results->num_rows == 0) {
echo "true"; //good to register
} else {
echo "false"; //already registered
}
}
else { echo "false"; //invalid post var }
?>
0 comments:
Post a Comment