Well, after an arduous research, and a huge hassle, I was able to solve the problem, and I leave here the solution in case someone needs to use validationEngine
with checkBox
....
To use validationEngine
in checkBox
it is necessary to create inputs
as array
in HTML
like this:
<input class="validate[required]" type="checkbox" name="group1[]" id="maxcheck1" value="a" onclick="checar(this.id)"/>
<input class="validate[required]" type="checkbox" name="group1[]" id="maxcheck2" value="b" onclick="checar(this.id)"/>
<input class="validate[required]" type="checkbox" name="group1[]" id="maxcheck3" value="c" onclick="checar(this.id)"/>
The array is defined in name="group1[]"
[I did not know this, you can create vectors in HTML in this way, as knowledge]
On the PHP side I use:
$_POST["maxcheck1"] = 0;
$_POST["maxcheck2"] = 0;
$_POST["maxcheck3"] = 0;
$checkBox = $_POST['group1'];
if ($checkBox) {
$i = 0;
foreach ( $checkBox as $value ) {
switch ($value) {
case "maxcheck1" :
$_POST["maxcheck1"] = 1;
break;
case "maxcheck2" :
$_POST["maxcheck2"] = 1;
break;
case "maxcheck3" :
$_POST["maxcheck3"] = 1;
break;
default :break;
$i++;
}
}
}
And finally, to recover these values in my form I use the functions:
function checkar() {
var idsObj = new Array("maxcheck1", "maxcheck2", "maxcheck3");
for (var i = 0; i < (idsObj.length); i++) {
if (document.getElementById(idsObj[i]).value == 1) {
//$(idsObj[i]).prop("checked", true);
document.getElementById(idsObj[i]).value = idsObj[i];
document.getElementById(idsObj[i]).checked = true;
} else {
//$(idsObj[i]).prop("checked", false);
document.getElementById(idsObj[i]).value = 0;
document.getElementById(idsObj[i]).checked = false;
}
}
}
function checar(idObj) {
val = idObj;
idObj = "#" + idObj;
if ($(idObj).is(':checked')) {
$(idObj).val(val);
} else {
$(idObj).val(0);
}
}