How to send values by GET other than those in the form?

3

I have a form to send data by GET and I want to send an additional data annexing it to the URL, the code is:

<form action="/Libro?accion=salvar" method="get">

        <label for="titulo">Titulo</label>
        <br>
        <input type="text" id="titulo"  name="titulo">

        <br>
        <br>

        <label for="categoria">Categoria</label>
        <br>
        <input type="text" id="categoria" name="categoria">
        <br>

        <input type="submit" value="Guardar cambios">

    </form>

When I give him submit the following url is sent:

Libro?titulo=Inferno&categoria=Literatura

But the variable accion=salvar that I want to send is not sent, I do not know how to send that additional variable to the other page in the same url.

    
asked by Fabian 18.11.2016 в 18:09
source

3 answers

4

Add a field hidden

<input type="hidden" name="accion" value="salvar">

You complete code:

<form action="/Libro" method="get">

    <label for="titulo">Titulo</label>
    <br>
    <input type="text" id="titulo"  name="titulo">
    <br>
    <br>
    <label for="categoria">Categoria</label>
    <br>
    <input type="text" id="categoria" name="categoria">
    <br>
    <input type="hidden" name="accion" value="salvar"><!-- !! -->
    <input type="submit" value="Guardar cambios">
</form>
    
answered by 18.11.2016 / 18:13
source
1

You can send it this way:

<input type='hidden' name='accion' value='salvar' />
    
answered by 18.11.2016 в 18:13
1

First, in your action you should not include the GET method by URL , you are already stating that you are going to send the form by GET method.

You can include a input of type hidden and that's where you add the value to save.

Although you may use the GET method, you would use the POST method, the difference is the way to send the data, GET send the data using the URL and POST send them by standard input and does not show anything in your URL .

<form action="./Libro" method="POST">

    <label for="titulo">Titulo</label>
    <br>
    <input type="text" id="titulo"  name="titulo" />

    <br>
    <br>

    <label for="categoria">Categoria</label>
    <br>
    <input type="text" id="categoria" name="categoria" />
    <br>

    <input type="hidden" name="tu_identificador" value="salvar" />

    <input type="submit" value="Guardar cambios" />

</form>
    
answered by 18.11.2016 в 18:39