I'm making a relatively simple form in which I use the plugin multiple-select
.
This is the form:
<form id="frmDatos" class="form-horizontal" action="txartelak.php" method="post">
<input type="submit" class="btn" id="salida" name="salida" value="<?php echo $lang["BUSCAR"] ?>" onclick="alert('Pulsado')">
<a href="listados.php" class="btn btn-danger"><?php echo $lang["VOLVER"]?></a>
<div class="form-body">
<div class="form-group">
<div class="row">
<!-- Año escolar -->
<label class="col-md-2 col-sm-12 control-label" for="annoMostrar"><?php //echo $lang["AÑOACADEMICO"] ?></label>
<div class="col-md-2 col-sm-12">
<input id="annoMostrar" maxlength="4" name="annoMostrar" type="text" class="form-control" value="<?php //echo $annoMostrar ?>">
</div>
<div class="col-md-2 col-sm-12">
<input id="annoSig" maxlength="4" name="annoSig" type="text" class="form-control" disabled>
</div>
<!-- Falta añadir multiselect de alumnos y etapa -->
</div>
<div class="row">
<div class="col-2">
<label class="col-md-2 col-sm-12 control-label" for="annoMostrar"><?php echo "ALUMNO"//$lang["AÑOACADEMICO"] ?></label>
</div>
<div class="col-6" style="padding-top:10px;">
<select id="alumnos" style="width:100%" id="alumnos" name="alumnos[]" class="js-example-basic-single" multiple="multiple" style="height: 30px" >
<?php foreach ($filtroUsuarios as $monitores) { ?>
<option value="<?php echo $monitores["USCOD"]; ?>" ><?php echo $monitores["USCOD"]."-".$monitores["SNOM"]; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="col-md-2 col-sm-12 control-label" for="annoMostrar"><?php echo "ETAPA"//$lang["AÑOACADEMICO"] ?></label>
</div>
<div class="col-6" style="padding-top:10px;">
<select id="etapas" style="width:100%" id="etapas" name="etapas[]" class="js-example-basic-single" multiple="multiple" style="height: 30px">
<?php foreach ($filtroEtapas as $monitores) { ?>
<option value="<?php echo $monitores["ETCOD"]; ?>"><?php echo $monitores["ETCOD"]."-".$monitores["ETDESCE"]; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row">
<div class="col-2" >
<label class="col-md-2 col-sm-12 control-label" for="annoMostrar"><?php echo "CURSO"//$lang["AÑOACADEMICO"] ?></label>
</div>
<div class="col-6" style="padding-top:10px;">
<select id="cursos" style="width:100%" id="cursos" name="cursos[]" class="js-example-basic-single" multiple="multiple" style="height: 30px">
<?php foreach ($filtroClase as $monitores) { ?>
<option value="<?php echo $monitores["SCLASE"]; ?>"><?php echo $monitores["SCLASE"]?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="col-md-2 col-sm-12 control-label" for="annoMostrar"><?php echo "CLASE"//$lang["AÑOACADEMICO"] ?></label>
</div>
<div class="col-6" style="padding-top:10px;">
<select id="clases" style="width:100%" id="clases" name="clases[]" class="js-example-basic-single" multiple="multiple" style="height: 30px">
<?php foreach ($filtroGrupo as $monitores) { ?>
<option value="<?php echo $monitores["SGRUPO"]; ?>"><?php echo $monitores["SGRUPO"]?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-12 text-right">
</div>
</div>
</div>
</form>
The problem is as follows, the selects
<select id="etapas" style="width:100%" id="etapas" name="etapas[]" class="js-example-basic-single" multiple="multiple" style="height: 30px">
<?php foreach ($filtroEtapas as $monitores) { ?>
<option value="<?php echo $monitores["ETCOD"]; ?>"><?php echo $monitores["ETCOD"]."-".$monitores["ETDESCE"]; ?></option>
<?php } ?>
</select>
I load them with a query that I have previously made, this is loaded correctly, then I implemented the plugin.
$("#alumnos").multipleSelect({
filter: true,
multiple: true
});
$('#alumnos').multipleSelect('checkAll');
This works without problems and does not give me any type of error, or javascript, jquery or PHP.
Now, at the time of clicking the submit, depending directly on the place where the form is working or not.
This is because the indices are not defined after the first select. To verify this I have done it in the following way.
if(isset($_POST['salida'])){
echo $_POST['salida'];
$alumnos = $_POST['alumnos'];
for($i==0;$i<count ($alumnos);$i++){
echo $alumnos[$i];
}
$etapas = $_POST['etapas'];
for($i==0;$i<count ($etapas);$i++){
echo $etapas[$i];
}
$cursos = $_POST['cursos'];
for($i==0;$i<count ($cursos);$i++){
echo $cursos[$i];
}
$clases = $_POST['clases'];
for($i==0;$i<count ($clases);$i++){
echo $clases[$i];
}
}
This returns the following on the screen
Search
"The code of the selected students"
Notice: Undefined index: stages in /var/www/html/txartelak.php on line 262
Notice: Undefined index: courses in /var/www/html/txartelak.php on line 266
Notice: Undefined index: classes in /var/www/html/txartelak.php on line 270
If you placed the input after the first select, the form is not sent because this index is not defined either. The problem seems to be from the plugin, but I have already used it in another form and it has not given me any problem.
Therefore I see two possible solutions to which I hope that someone can give the answer.
EDITION
I have done a few more tests and I have realized that this happens when I select a lot of options in the select. The fault is where it is, what it is and the reason I need to know how to solve it.
EDITION 2
From the first edition, to know that the error depended directly on the number of results, I have tested what is the total number of selections that must be made for the error to occur, this error jumps exactly when you select 1000 checkbox.