PHP does not receive parameters after submit

1

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.

  • It's a long and tedious code to understand why I might have a fault I have not seen.
  • The possibility of using another plugin that has the same feature of selecting all through a checkbox, not of problems with PHP.
  • 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.

        
    asked by Lombarda Arda 04.05.2017 в 15:35
    source

    1 answer

    2

    Long answer:

    I tried your code locally and I failed from 2,500 selected elements. That led me to think that the problem could be more browser or server configuration (web server or PHP) than a problem with the code.

    Then I tried local with Chrome, Firefox and Internet Explorer and I found that all of them failed from the same number of selected elements (2500). With that I ruled out that it was a browser error and I focused on the configuration of the server.

    Then I opened the PHP configuration (in the file php.ini ) and found that there is this row:

    ; How many GET/POST/COOKIE input variables may be accepted
    max_input_vars = 2500
    

    That is, the maximum number of variables that can be passed in GET, POST or with a cookie is 2500. The number that dallo gives me! I increased that number to 250000 and it works for me.

    Doing some online research, it seems that the default value of that variable in PHP = 5.4 is 2500 (which would match the value I receive).

    If you keep getting errors, that could be because you are reaching the limits at other points. There are other variables that control the size that can be sent in the POST ( post_max_size ), try increasing its value to see if it works for you.

    tl; dr;

    Increase the number of variables that you can pass through GET / POST / COOKIE because that is surely the reason. You can do it in php.ini by changing the value of max_input_vars :

    ; How many GET/POST/COOKIE input variables may be accepted
    max_input_vars = 250000
    
        
    answered by 04.05.2017 / 17:28
    source