I have an issue on my dynamic generated text box. I want required and remote validation for all text box.
HTML
<li>
<label class="label">name 1</label>
<input type="text" name="name_1" id="name_1" class="req_aap" value="" />
<label id="aap_error" class="error"></label>
</li>
<li>
<label class="label">name 2</label>
<input type="text" name="name_2" id="name_2" class="req_aap" value="" />
<label id="aap_error" class="error"></label>
</li>
<li>
<label class="label">name 3</label>
<input type="text" name="name_3" id="name_3" class="req_aap" value="" />
<label id="aap_error" class="error"></label>
</li>
<li>
<label class="label">name 4</label>
<input type="text" name="name_4" id="name_4" class="req_aap" value="" />
<label id="aap_error" class="error"></label>
</li>
................can be any number of fields................
JS
$.validator.addClassRules("req_aap", {
required:true,
remote:{
url: "some_ajax.php",
type: "post",
data: {
name: function() {return $(this).val();},
tblNM:'someTable'
},
complete: function(data){
return data;
}
}
});
some_ajax.php:
if(isset($_REQUEST['name'])) {
if(getValFromTbl('name',$_REQUEST['tblNM'],'name="'.addContent($_REQUEST['name']).'"'.$fld)!='')
{
$valid = 'false';
}
else {
$valid = 'true'; // Allowed
}
echo $valid;
}
getValFromTbl
is the function which return record already exist or not.
This works fine.
I got true and false exactly as i want but then also my jQuery validation continually gives error. It always go to false condition and gives validation error if I enter true value then also it gives error.