I am trying to construct a JS on the fly for a remote validator function using the validation plugin. but for some reason, it's not converting the JS as an object and is treating it as a string and embedding double quotes.
Ex:
The PHP code I have is:
$remoteUrl = '/test/checkusername';
$remoteValidatorJs = "{url: '". $remoteUrl . "',
type: 'post',
async:false,
dataType: 'html',
beforeSend: function(){
alert('Validating Form Field');
},
complete: function(){
alert('Completed Validation of Form Field');
},
dataFilter: function(html) {
return html;
}
}";
$validation[ 'rules' ][ 'Name' ][ 'remote' ] = $remoteValidatorJs;
How do I frame or convert the JS in $remoteValidatorJs variable so, it eventually looks like the content in the following "remote" section, when the array is printed:
$("#testForm").validate( {
"rules":{
"Name":{
"remote":{
url: '/test/checkusername',
type: 'post',
async:false,
dataType: 'html',
beforeSend: function(){
alert('Validating Form Field');
},complete: function(){
alert('Completed Validation of Form Field');
},
dataFilter: function(html) {
return html;
}
}
}
}
} );
Thanks,
$remoteValidatorJs = "- this will make the entire variable a string