Well, after a lot of hard research and a lot of work, I was able to solve the problem, and I leave here the solution in case someone needs to use the validationEngine
with checkBox
....
To use the validationEngine
in checkBox
it is necessary to create the inputs
as a array
in HTML
thus:
<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 didn’t know this, that you can create vectors in HTML 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);
}
}
I think the question is missing: show the PHP Submit, put this tag and give a descriptive title
– brasofilo
I edited @Brasofilo, and now? rs
– MarceloBoni
You say the problem is in the Validation Engine, which is a jQuery plugin, speaks of PHP, but shows neither PHP nor jQuery... What is the difficulty?
– brasofilo
@brasofilo . . . Validation Engine works like a class.... it works with the name of the
input
and with thevalidate[minCheckbox[2]]
of the attributeclass
– MarceloBoni
@brasofilo PHP has already said... it recovers the group of
checkBox
as if the$_POST['group1']
were 1, it does not recover theID
of each, and yes the whole group..... I think it was your lack of attention, not poorly formulated question– MarceloBoni