how to capture name and value of a select without javascript

0
   <label for="">Codigo Motivo</label>
                        <select required name="cmotivo" class="form-control" id="cmotivo">
                            <option value="01" selected>Anulacion</option>
                            <option value="02">Devolucion</option>
                            <option value="03">Correccion</option>
                            <option value="04">Descuento</option>

                        </select>

when I receive by post

$codigo = $_POST['cmotivo']. $descripcion = $_POST[''] ?
    
asked by Fernando Abel Gonzales Ch 13.02.2018 в 18:05
source

1 answer

1

It is not possible , at least not in the way you suggest it.

When submitting HTML forms, a <select> is sent only the value attribute of the selected% or <option> .

You should do some "trick" to not use JavaScript, there are many options, then I show two:

  • Send the two "masked" data in the value attribute, as if they were serialized:

    <option value="01-anulacion">Anulacion</option>
    

    Already in PHP the corresponding split would be made.

  • Have an array in the backend that recognizes the values sent:

    $valores = ['01' => 'Anulacion', '02' => 'Devolucion', ...
    

    Upon receiving the value (s), the texts are obtained from the arrangement.

  • answered by 13.02.2018 в 18:28