Parameters in form action are not sent by GET method

Asked

Viewed 1,318 times

0

Uni multiple GET at the same URL smoothly, all using BUTTON.

http://localhost/test/choose_day.php? Inst=teste&sala=sala01&ano=2016&mes=janeiro using

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

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

Only I need the previous GET’s in that same URL to send by email.

I complete the form action with the previous GET.

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

On the next page insert 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 accuses errors

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

What might be going on?

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

  • When I send the separate data everything works. The problem is when I want to send the checkbox data together with the button data. There’s the general error.

2 answers

2


When you use GET in forms you need to pass the 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>
  • It is almost ready. Now I will make a explode p/ make an echo of this data and send by email. I even published another question with these almost full pages but the answer is the same. Thank you very much.

  • @ufrrj99 and what’s missing?

  • I will try to do the Snippets and the email form. Then I will learn how to make the database and include it all together.

  • @ufrrj99 understand, but the problem of sending inputs you managed to solve with the explanation? This sent now correctly?

  • 1

    Now it’s on show.

  • @ufrrj99 Ah got it now, you were testing, I’m glad it worked out. See you more =)

Show 1 more comment

0

Two simple examples to solve:

Button with onclick event

Can resolve simply with an event button "onclick"

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

Sending by POST method and redeeming $_GET

Modify the GET method to 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 your case because it is less invasive, that is, it will make virtually no changes in the codes. Just need to change get for post in the action of form

Browser other questions tagged

You are not signed in. Login or sign up in order to post.