Switch case on submit button according to button ID

0

I have 7 submit buttons on a form. Being:

Four of that:

<input type="submit" id="chamado1" class="mr-abre-btn" value="Abrir chamado">

Two of these:

<input type="submit" id="chamado2" class="mr-abre-btn" value="Encaminhar chamado">

And one of these:

<input type="submit" id="chamado3" class="mr-encerra-btn" value="Encerra chamado">

The problem is that I am trying to make a switch case or an if in value of a input hidden that I have. I'm doing it this way:

<input type="hidden" name="situacao_id" value="
<?php
    $situacao_chamado = $_POST['id'];
            switch ($situacao_chamado) {
                    case 'chamado1':
                        echo "1";
                        break;
                    case 'chamado2':
                        echo "3";
                        break;
                    case 'chamado3':
                        echo "3";
                        break;
                }
                ?>"

However, when I search for this variable:

$situacao_chamado = $_POST['id'];

It ends up generating the error below:

Notice: Undefined index: id in C:\wamp64\www\form\formulario.php on line 167 Call Stack #TimeMemoryFunctionLocation 10.0010242264{main}( )...\formulari.php:0 20.0111307088include( 'C:\wamp64\www\form\formulario.php' )...\formulario.php:44 "> 
    
asked by anonymous 19.10.2017 / 22:20

2 answers

1

This error occurs because the $_POST['id'] looks for an input that has name="id" , it is enough to arrange its inputs by putting a name , so it will get the inputs that have name="id" and give them the values determined by value=""

<input type="submit" name="id" id="chamado1" class="mr-abre-btn" value="Abrir chamado">

<input type="submit" name="id" id="chamado2" class="mr-abre-btn" value="Encaminhar chamado">

<input type="submit" name="id" id="chamado3" class="mr-encerra-btn" value="Encerra chamado">

In your PHP just change the case:

switch ($situacao_chamado) {
    case 'Abrir chamado':
        echo "1";
        break;
    case 'Encerrar chamado':
        echo "3";
        break;
    case 'Encaminhar chamado':
        echo "3";
        break;
}

This should solve your problem however I believe it would be best to put radioButtons and just an input submit

    
19.10.2017 / 23:43
-1

None of the inputs you put have id="id" that you use in $ _POST ['id']. So he is saying that there is no pq really was not defined.

    
19.10.2017 / 23:24