submit button turn a normal link

2

I need a button with its same values to be "converted" to a normal Link.

<input type="submit" name="idPessoa" id="idPessoa" class="text-success" 
       value="<?php echo $this->idPessoa = $lotacao[$i][3];?>">

Is there any effective way to do this? I tried one or the other, but with no expected success.

    
asked by anonymous 18.09.2014 / 19:11

3 answers

3

If you really need a link

Just use this format:

<a href="#" onclick="document.nomeDoSeuForm.submit(); return false;">

Applying to your case:

<a href="#" onclick="document.nomeDoSeuForm.submit(); return false;"><?php
   echo htmlentities( $this->idPessoa = $lotacao[$i][3] );
?></a>

Note that the htmlentities() I added has nothing to do with the question, but it's good to use it to make the accent OK. If your variables are already encoded, you can remove them.

If you just need the look of the link

Just use input normal in form, or even button :

<input type="submit" name="idPessoa" id="idPessoa" class="meulink" 
   value="<?php echo $this->idPessoa = $lotacao[$i][3];?>">

And stylize with CSS:

.meulink {
   display:inline;
   background:transparent;
   text-decoration: underline;
   border: none;
   cursor: pointer;
   color: #00f;
}

See working at JS Fiddle

    
18.09.2014 / 22:04
2

Simply build a normal link, which will take you to the form page, passing everything you want by GETs directly into the URL.

Build the link, taking the value of the form's action and add the input submit information, passing that value to a GET.

In your case, something like this:

<a href="http://linkdoform.com.br/pagina.php?idPessoa=<?php echo $this->idPessoa = $lotacao[$i][3];?>"> Nome da ação</a>
    
20.09.2014 / 09:16
1

To do this I advise you to use jQuery, follow a small example of how I would do this, remembering that you will need to import the jQuery library. I used input hidden , passing the value of it on the submit with attribute .val .

HTML form with jQuery that can be either min or uncrompressed.

<script src="js/uncrompressed/jquery-1.11.1.js"></script>
<form method="post">

    <input type="text" name="txtNome" />
    <input type="hidden" id="valor" name="valor" />
    <input type="submit" onclick="$('#valor').val('opcao1')" value="Opção1" />
    <input type="submit" onclick="$('#valor').val('opcao2')" value="Opção2" />
    <input type="submit" onclick="$('#valor').val('opcao3')" value="Opção3" />

</form>

And the PHP code I used:

<?php

    if($_POST){

        $getNome = $_POST["txtNome"];

        $valorDoBotao = $_POST["valor"];

        if($valorDoBotao == "opcao1"){
            header('Location: seulink?nome='.$getNome);
            // faca isso
        }

        if($valorDoBotao == "opcao2"){
            header('Location: seulink?nome='.$getNome);
            // faca isso
        }

        if($valorDoBotao == "opcao3"){
            header('Location: seulink?nome='.$getNome);
            // faca isso
        }
    }

?>
    
18.09.2014 / 20:13