perhaps this is the most silly question but I really don't know how to solve this problem.
I'm using parsley.js and I did a password field validation using parsley's data-remote:
View snippet:
<form data-parsley-validate novalidate class="form-horizontal group-border-dashed" id= "form-val" role="form" action="{site_url()}admin/checkPass" method="post" enctype="multipart/form-data">
<div class="form-group">
<div class="col-sm-4">
<label>Contraseña Actual</label>
</div>
<div class="col-sm-7">
<input id="actualPass" type="password" name="actualPass" data-parsley-remote="{site_url()}admin/checkPass" data-parsley-remote-options="POST" data-remote-datatype="jsonp" class="form-control" required>
</div>
</div>
On my admin.php:
public function checkPass(){
if (isset($_POST['actualPass'])) {
$passMd5 = md5($_POST['actualPass']);
$pass = ($this->data['actualUserBack']->user_password);
if ($passMd5 == $pass) {
echo json_encode(true);
}else{
echo json_encode(false);
}
}
}
I have other fields (new password and retype new password) that works super with this parsley's validation. When you input wrong passwords then a message in red appears.
What I want to have is the same red box with a custom message in the first validation I've made. From admin.php/checkPass I'm only returning true and false in a blank page.
How do I do to use parsley validation format in that case?
Here I attach images:
What shows first checkPass function: image 1
How I want it to look: image 2
How do I send the data? what do I have to modify or add? thanks!
You'll have two possibilities:
modifying your backend script to return not anymore a true/false
result, but a 200
and 400
status code. Parsley remote validator by default acknowledge 200
response as a good validation, and all others as failures
defining your own parsley remote validator (see custom remote validator section here: http://parsleyjs.org/doc/index.html#remote ) where you will check not anymore the response status but the response content, looking for your boolean answer.
Hope that helped.
Best
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.