i’m new to jquery, trying to add a validation rule to my email input. It checks if email is in database or not.
my html input i’m trying to add validation rule to.
<input id="email" name="email" type="text" class="easyui-validatebox" validType="email" required="true" >
MY JS
$("#regform").validate();//block below was nested in validate in OP
$('input[name="email"]').rules("add",
{
remote :
{
url: 'checkMaila.php',
async: false,
type: "POST",
data:
{
email: function()
{
return $('input[name="email"]').val()
}
}
}
});
MY PHP
<?php
/* check if email is already registered */
//connect to db using mysqli
include 'conn.php';
if(isset($_POST['email']))
{
//op had this line instead of the line below:$maila= $_POST['email']
$maila = $mysqli->real_escape_string($_POST['email']);
//op line changed to one below $result = mysql_query("select * from user where email= '"+$maila+"';");
$sql = "SELECT * FROM user WHERE email = '".$maila."'";
$result = $mysqli->query($sql);
if($result->num_rows == 0){
echo "true";
}
else
{
echo "false";
}
}
else
{
echo "false"; //invalid post var
}
?>
more info:
my inline validation rules work as they should. my js code is in external js file which contains other js functions using jquery, they work.
The following answer is for this much earlier revision of the OP:
https://stackoverflow.com/revisions/13380448/2
You should not have
.rules()nested inside of.validate(). As per documentation,.rules()must also appear someplace after.validate()is invoked.http://docs.jquery.com/Plugins/Validation/rules