Button Submit turn a normal link

Asked

Viewed 7,456 times

2

I need a button with the 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 unsuccessfully expected.

  • You cannot pass this information on to an Hidden input?

  • I tried something like this.. I placed the Hidden button, and created the <a href="javascript:Document.form.Submit();" id="person"> XXXXX </a> but it wasn’t. It works, but it’s like I caught the same ID so if I click another button of another ID will call the same previous one.

  • Do you have several Foms? And you want the Submit input to turn into a <a href="javascript:Document.form.Submit();" id="person"> XXXXX </a> to submit this form in specific?

  • It’s just a form that I have.. and three buttons that call different Ids. And I want to make them link, but they have to have a button action. (Weird kkk)

  • Why does it have to be a link? What is the problem you have to solve? What is the result you expect from clicking on the link? What data do you need to send to the server? Sorry for all these questions. But without the answers I cannot understand what you want.

  • Finding that bootstrap has something that already fools cool... <button type="Submit" name="idPessoa" id="idPessoa" class="Bt btn-link" style="color: red value="<? php echo $this->idPessoa = $capacity[$i][3];? >">Failed</button>

  • @phpricardo updated the answer with a CSS solution as well.

Show 2 more comments

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() which 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.

If you only need the look of the link

Just use the input normal in form, or even a button:

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

And styling with CSS:

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

See working on JS Fiddle

2

Simply build a normal link, which leads to the form page by passing everything you want through Gets, directly into the URL.

Construct the link by taking the value of the form action and add the Submit input information, passing this value through a GET.

In your case, something like that:

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

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 a input hidden, passing its value in Submit with attribute .val.

HTML form with jQuery which can be 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
        }
    }

?>
  • 1

    Thanks for the intention bro, but ai you are still using BUTTON what I want is to use LINK

  • You want to use an Submit link in the form by sending the parameters to this link?

  • I guess that’s right. :]

  • But the way I showed it forwards to a link using the header('Location : seulink'.$parameter.), I believe you wanted to.

  • I have researched this and you have a question similar to yours on this link, http://stackoverflow.com/questions/7022167/jquery-add-post-variables-to-a-href-link

Browser other questions tagged

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