I'm using jQuery validate plugin in my form. Validation works fine except when I'm using this 'data' function to send data. When I comment out this data section, form is submitted and redirected properly and other validation is implemented properly. But using data , form is submitted and redirected to blank page.
Validation for checking duplicate email in database is checked here.. With the following data function, validation is working but the submission is not working.
Here's my part of validation script:
personal_email: {
email: true,
remote: {
param:{
url: app.baseurl('user/check_personal_email'),
type: 'POST',
data:
{
userID : function()
{
return $("#userID").val();
}
}
}
// ,
// depends: function(element)
// {
// return ($('#editTrue').val() == undefined && $('#editTrue').val() == null);
// }
}
},
Controller function that handles and returns the above url request is :
public function checkPersonalEmailExists($f3)
{
$userID = $f3->get('POST.userID');
$email = $f3->get('POST.personal_email');
$user = new UserModel();
$records = $user->checkIfPersonalEmailExists($email);
if(count($records) > 0)
{
foreach ($records as $record)
{
$user_id = $record['id'];
}
echo ($userID == $user_id) ? 'true' : 'false';
}
else
{
echo 'true';
}
}
Here's my HTML form:
<form method="post" action="user/save" id="employee-form">
<input name="personal_email" type="email" class="form-control" id="personal_email">
<button type="submit" class="btn btn-primary" name="update" value="update">Update User</button>
</form>
Form submission is handled by following function:
public function save($f3)
{
$save = $f3->get('POST.save');
$update = $f3->get('POST.update');
if(isset($save) || isset($update))
{
echo 'It is working';
// saving to database stuff...
exit;
}
else
{
echo 'It is not working';
exit;
}
}
One thing I noticed is that when every elements are filled with valid data.. then only it is acting this way. Else, it is displaying 'It is working'.
It seems that with data in validation, submit button value is not recognized.. It displays 'It is not working'.
I cannot figure out what's wrong, and how jQuery validation plugin behaves.
Please help me with this. Any help is very much appreciated. Thanks.