I have tried all the possible approaches found, but I am struggled to get the default remote validator working.
I'm just trying to achieve to check if the mail for a registration page of a user is duplicated. Thus, I declare the input as follows:
<input type="email" name="email" required
placeholder="Dirección de correo"
data-parsley-trim-value="true"
data-parsley-trigger="change"
data-parsley-remote-options='{ "type": "POST", "dataType": "jsonp" }'
data-parsley-remote="checkmail.php"
data-parsley-remote-message="Mail duplicated"
class="form-control">
The checkmail.php code is:
require_once("../functions/mysqli_connect.php");
if (empty($_POST['email'])){
$errors[] = 'No llega el parametro de mail';
}else {
$email = trim($_POST['email']);
$q = ("select * from register where email ='" . $email . "'");
$r = mysqli_query($dbc, $q);
if ($r) {
if (($r->num_rows) > 0) {
echo json_encode(404);
} else {
echo json_encode(200);
}
}
}
I've tried multiple combinations for echo response, I've read all the messages on stackoverflow but couldn't find the solution because I've always get the message : This value seems to be invalid.
As I read on another's user question I've tried:
data-parsley-remote-message="Mail duplicated"
but with no luck either.
The PHP code works as expected, so no errors there, but Parsley always treats the json_encode responses as it is was an error.
Any help would be vey appreciated.
Thanks in advance.