Join href to a button

0

In a fomulário I have this link:

 <a href="chk-gerente.php?nro_pergunta=<?php  echo $nro_pergunta; ?>">Próximo</a>

And this button:

 <button  type="submit"  class="btn btn-default" >REPONDER</button>

Please try again later.  This is a system of questions, which list asks the question.  The next link brings up the new question and the responder does the GET method by inserting it into the database.  Is it possible to pass the next link inside the button doing one thing? type, when I click on answer it would do the insert and soon after would bring the next question?  Something like this:

 <button a href="chk-gerente.php?nro_pergunta=<?php  echo $nro_pergunta; ?>" 

type="submit"  class="btn btn-default" >REPONDER</button>

I've tried it that way and it did not work.

    
asked by anonymous 13.02.2016 / 03:11

3 answers

0

You can use a JQuery (or Javascript) to make default link opening with href on button

    $("button").click(function() {

      if ($(this).attr("href")) {
        alert('Irá redirecionar para ' + $(this).attr("href"));
        window.location.href = $(this).attr("href");
      }

    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonhref="chk-gerente.php?nro_pergunta=1" type="submit" class="btn btn-default">REPONDER</button>

However for your specific case you can create a input hidden and then redirect the person.

For example:

HTML:

<form action="" method="get">
<input type="hidden" name="proxima" value="<?= $nro_pergunta ?>" />
<button type="submit"  class="btn btn-default" >REPONDER</button>
</form>

PHP:

<?php

if(isset($_GET['proxima'])){

//...

$pergunta = (int)$_GET['proxima'];
// Número da pergunta (se não for número remove o (int)!)

header('location: chk-gerente.php?nro_pergunta='.$pergunta);
// Redireciona    
}

?>

In this way, you will get nro_pergunta of hidden and will redirect to the chosen URL.

    
13.02.2016 / 08:41
0

You have to put the link inside the button, try to put it like this:

<button type="button"><a href="URL.php">responder</a></button>
    
13.02.2016 / 06:11
0

Thank you guys for the tips, I tested them and gave them right, but the one that was exactly what I needed was the @hgfdgd:

when you have a button, embed it in a form: <form action=YOUR_URL method=get> <input type=hidden name=nro_pergunta value=<?php echo $nro_pergunta; ?> <button...> </form> see also:

Thank you very much everyone.  Strong hug.

    
13.02.2016 / 13:00