Parameters in form action are not sent by GET method

0

I put several GETs in the same URL without any problems, all using BUTTON.

link using

<?php
$acao = $_GET['inst'];
$acao2 = $_GET['sala'];
$acao3 = $_GET['ano'];
$acao4 = $_GET['mes'];
?>

The next GET would be 5 checkbox inside a FORM. If I use <form action="confirmar.php" method="get"> then all OK, the http://localhost/teste/confirmar.php?values[]=18&values[]=28&values[]=38 result appears.

I just need the previous GETs at the same URL to send via email.

I complete the form action with previous GET.

<form action="confirmar.php?&inst=<?=$acao;?>&sala=<?=$acao2;?>&ano=<?=$acao3;?>&mes=<?=$acao4;?>&diahora=<?=$value;?>';"'

On the next page I enter the GET:

<?php
$acao = $_GET['inst'];
$acao2 = $_GET['sala'];
$acao3 = $_GET['ano'];
$acao4 = $_GET['mes'];
$acao5 = $_GET['diahora'];
?>

When I update the site and click on the button it acknowledges the errors

  

Notice: Undefined index: inst, room, year, month, and day

What could be happening?

If you can send the GET of checkboxes without using form, just by button, it can be also because they are not logged in users, only site visitors.

    
asked by anonymous 06.04.2016 / 02:42

2 answers

2

When using GET in forms it is necessary to pass values to inputs, like this:

<?php
$acao = $_GET['inst'];
$acao2 = $_GET['sala'];
$acao3 = $_GET['ano'];
$acao4 = $_GET['mes'];
$acao5 = $_GET['diahora'];
?>
<form action="confirmar.php">
<input name="inst" value="<?=$acao;?>">
<input name="sala" value="<?=$acao2;?>">
<input name="ano" value="<?=$acao3;?>">
<input name="mes" value="<?=$acao4;?>">
<input name="diahora" value="<?=$acao5;?>">

If you are selects you will have to do something like (this is just an example to understand and adapt):

<?php
$options = array(
    'Valor 1' => '1',
    'Valor 2' => '2',
    'Valor 3' => '3',
    'Valor 4' => '4'
);

$campo1 = empty($_GET['campo1']) ? null : $_GET['campo1'];
?>
<form action="">

    <select name="campo1">

    <?php foreach ($options as $descricao => $value): ?>

        <option <?=($campo1 === $value ? ' selected' : '');?> value="<?=$value;?>"><?=$descricao;?></option>

    <?php endforeach; ?>

    </select>

    <button type="submit">Enviar!</button>

</form>
    
06.04.2016 / 03:03
0

Two simple examples to solve:

① Button with onclick event

Can be solved simply with an onclick event button

<input type="button" onclick="location.href='pagina.php?foo=1&bar=ok';" value="envia">

② Sending by POST method and rescuing $ _GET

Modify the GET method for POST.

<form action="pagina.php?foo=1&bar=ok" method="post">
<input type="submit" value="send">
</form>

Why does it work?

The reason is that the URL defined in the action attribute is always sent by the GET method, regardless of whether the action attribute is set to POST.

This mode may be the most ideal for you because it is less intrusive, meaning you will not make any changes to the codes. You just need to swap get with post in action of form

    
06.04.2016 / 05:37