Getting equal variable values from URL

0

I have complicated the title a little to explain my doubt, but I will try to be as clear as possible.

I have this field:

Ineedtogetthevaluesthatwereselectedintheextensionsfield,butwhenIgettheresultviaPOSTitonlyreturnsavalueandviaGETalso,butitbringsittotheURL:

https://192.168.0.27/projetos/bdm/grupo_de_permicao.php?formfield1=teste&my_multi_select1=200&my_multi_select1=4864&my_multi_select1=2000

Iwantedtoknowifyoucangetallthesevalueswiththesamevariablemy_multi_select1andplayinsideanarrayorsomeotherway.

Ithinkit'snotveryuseful,buthereismycodebelow:

<divclass="form-group">
                               <label class="form-label" for="formfield1">Ramais</label>
                                    <span class="desc">Adicione ou remova os ramais utilizando a caixa abaixo</span>
                                    <select name="my_multi_select1" class="multi-select form-control" multiple="" id="my_multi_select1" name="formfield2">

                                        <?php
                                $allramal = "";
                                $tst2 = selectRamals();
                                while ($linha = mysqli_fetch_array($tst2)) {
                                  ?>
                                    <option value="<?=$linha['extension']?>"><?=$linha['name']?>   (<?=$linha['extension']?>)</option>
                                <?php } ?>
                                    </select>      
                                </div>
    
asked by anonymous 28.03.2016 / 07:03

1 answer

2

I recommend via POST, because as we all know, GET has a character limit that depends on the browser, and if it is something that the client can make many selections, it may give problem via GET.

Do this (I did an example for your business, but without Bootstrap, to serve as a model for other people and make the code simpler, just re-adapt).

<form action="" method="post">
<select name="my_multi_select1[]" multiple="multiple">
    <?php
        $allramal = "";
        $tst2 = selectRamals();
        while ($linha = mysqli_fetch_array($tst2)) {
            echo "<option value='{$linha['extension']}'>{$linha['name']} ({$linha['extension']})</option>";
        }
    ?>
</select>

Note that in the input name, we put a [] to indicate to PHP that the variable that will receive the values of this field, must be an array.

To print on the screen, do:

print_r($_POST['my_multi_select1']);

Note: When you re-write the code, get the name of the input where you have the options, you have set the name property twice in the same field.     

28.03.2016 / 07:56