Doubt to redirect specific pages by window.location.href with if Else

Asked

Viewed 87 times

0

So I need to create a polling system: There are 5 options the best, good, regular, bad, bad questions. If user click on great, good, regular: stores the information and goes back to the index. If user click bad or bad stores information and go to second question enquete1_2.html stores and goes to index again. Information is already being stored in the bank.

<section>
     <?php 

    if(!empty($_GET['id']) && !empty($_GET['valor'])){
        $enquete_id = $_GET['id'];
        $valor_opcao = $_GET['valor'];

        echo'<h1>Opção <i>'.$valor_opcao.'</i> contabilizada com sucesso!</h1>
        <h2><a href="index.html">voltar à página inicial</a></h2>
        <h2><a href="enquete_info.php?id='.$enquete_id.'">Ver informações da enquete</a></h2>';
    }
    else
        header("location: main.php");
    ?>


<script type="text/javascript">
   valor_opcao = "valor"; 

if (valor_opcao == "id=1&valor=Ótimo") {
    window.location.href = "index.html";
} else if (valor == "id=1&valor=Bom") {
    window.location.href = "index.html";    
} else if (valor == "id=1&valor=Bom") {
    window.location.href = "index.html";    `
`
}else {
    window.location.href = "enquete1_2.html";    
}
</script>

    </div>

  </div>
  </section>  
</div>

  • Fernando expliqe better what you need. What is the purpose of your code?

  • So I need to create a polling system: There are 5 options the best, good, regular, bad, bad questions. If user click on great, good, regular: stores the information and goes back to the index. If user click bad or bad stores information and go to second question stores and go to index again.

  • Fernando, it’s not clear

  • So I need to create a polling system: There are 5 options the best, good, regular, bad, bad questions. If user click on great, good, regular: stores the information and goes back to the index. If user click bad or bad stores information and go to second question stores and go to index again.

  • ok, I get it. Is there more code besides this one? If you’ve edited your question for me to try to help you in a more precise way.

  • It’s not just that.

  • I’m missing the java script option I believe if I have an example in php I thank tbm.

  • ok, I’ll build in php and html for you and then you adapt as your need

  • OK thanks in advance

Show 4 more comments

1 answer

0


Fernando, follow a practical example to help you:

<!DOCTYPE html>
<html lang="pt-BR">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Site</title>
  <style>
    .container {
        width:50%;
        height:300px;
        margin:0 auto;  
    }
    input[type="radio"] {
        margin-left:30px;   
    }
  </style>
</head>

<body>
  <section class="container">
     <?php 
        if(!empty($_GET['id']) && !empty($_GET['valor'])){
            $enquete_id = $_GET['id'];
            $valor_opcao = $_GET['valor'];

            echo'<h1>Op??o <i>'.$valor_opcao.'</i> contabilizada com sucesso!</h1>
            <h2><a href="index.html">voltar ? p?gina inicial</a></h2>
            <h2><a href="enquete_info.php?id='.$enquete_id.'">Ver informa??es da enquete</a></h2>';
        }
        ?>
            <form method="post">
                <label>1) O que voce achou dos nossos servicos?</label><br>
                <input type="radio" name="opcao" value="otimo">Otimo<br>
                <input type="radio" name="opcao" value="bom">Bom<br>
                <input type="radio" name="opcao" value="regular">Regular<br>
                <input type="radio" name="opcao" value="ruim">Ruim<br>
                <input type="radio" name="opcao" value="pessimo">Pessimo<br>

                <input type="submit" name="resposta" value="Responder">

                <?
                if($_POST['opcao'] == 'otimo' or $_POST['opcao'] == 'bom' or $_POST['opcao'] == 'regular'){ ?>
                    <br><br>
                    aqui voce vai salvar na base de dados e vai redirecionar par ao index.html
                    este codigo volta:  
                    header("location: index.php");
                <?  
                } else { ?>
                <br><br>
                <!-- Aqui você armazena a informação no banco -->
                <label>2) Porque?</label><br>
                <textarea cols="50" rows="8"></textarea>
                <br>
                <input type="submit" name="resposta" value="Responder"> 
                <?  
                }
                ?>
            </form>
      </section>  
</body>

</html>
  • Leandro, thank you very much already gave me a light vlw !!!

  • Imagine, whatever thing we are there. Hug

  • Leandro can take a doubt?

Browser other questions tagged

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