How do I change screen content using php

Asked

Viewed 49 times

0

I have a system that has two possibilities of use for the user:

1.manual

2.automatica

wanted the user to be able to choose between these two versions in the style input type='radio'. So just updating the page with the content the customer chose (manual or automatic)

<body id="body">
    <div id="DivTopo">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                    include "TopoLogado.php";
                    ?>
                </div>
                <div> 
     <form action="Atividade.php">
    <INPUT TYPE="RADIO" NAME="OPCAO" VALUE="1">Kanban Automático
    <INPUT TYPE="RADIO" NAME="OPCAO" VALUE="2">Kanban Manual
    <input type="submit" value="atualizar">
    </form> 

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

    </div>
    <div id="DivCentral"><br>
        <h1 class="Titulo">Tarefas de <?php echo $tblDetalhes['nome_ATIVIDADE'] ?></h1>

        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">


                    <?php 
                    if($_POST["OPCAO"]==1 ){

                    include 'KANBAN1.php';

                    } else if ($_POST["OPCAO"]==2){
                         include 'KANBAN2.php';
                    }
                    ?>

                    <div id="DivRodape">
                        <?php include "Rodape.php"; ?>  
                    </div>
                </div>
            </div>
        </div>
    </div>
  <script>
 <?php
 include "./JavaScript/Modal.js";
 ?>
    </script>
</body>

I thought I’d do it that way too:

<div class="pre-spoiler">

<input id="xs" value="Leia Mais" style="margin-left: 50px; padding: 0px; width: 80px; " onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';this.innerText = ''; this.value = 'Ocultar'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.value = 'Leia Mais';}" type="button"> </div>

<div>

<div class="spoiler" style="display: none;">

<?php include 'KANBAN1' ?>

</div>

</div>

But the first one works, but the second one doesn’t (the same content of the first one appears)

  • Please post the code you have to supplement your question. This makes it easier for the community to help.

  • @Pauloimon ready

  • Wouldn’t just set up your <form> to send the values by POST to that same page? You are already making the condition with the received values. I don’t understand what your difficulty is.

  • is not working

  • 1

    Place: <form action="" method="post"> and testing.

  • @Pauloimon opa, that’s right +1 for your comment.

  • Good! Needing we are there.

Show 2 more comments

1 answer

0


If I understood what you want is that when after the person chooses an option that option is saved, this is it?

And it also has what @Paulo said, exchange the form for:

 <form action="" method="post">

The action="" will update the current page, so you won’t need to enter the URL

If this is the case then you can use cookies, it should look like your code:

<?php
if (!empty($_POST["OPCAO"])) {
     if ($_POST["OPCAO"] == 1 || $_POST["OPCAO"] == 2) {
        //Atualiza o valor quando o usuário solicitar (o cookie expira em um ano)
        setcookie('temakaban', $_POST["OPCAO"], time() + 31536000, '/');
        $_COOKIE['temakaban'] = $_POST["OPCAO"];
     }
}
?>
<html>

....

<body id="body">
    <div id="DivTopo">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                    include "TopoLogado.php";
                    ?>
                </div>
                <div> 
    <form action="" method="post">
    <INPUT TYPE="RADIO" NAME="OPCAO" VALUE="1">Kanban Automático
    <INPUT TYPE="RADIO" NAME="OPCAO" VALUE="2">Kanban Manual
    <input type="submit" value="atualizar">
    </form> 

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

    </div>
    <div id="DivCentral"><br>
        <h1 class="Titulo">Tarefas de <?php echo $tblDetalhes['nome_ATIVIDADE'] ?></h1>

        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">

                    <?php
                    //Por padrão usará KANBAN1, acaso o usuário não tenha escolhido
                    if(empty($_COOKIE["temakaban"]) || $_COOKIE["temakaban"] == 1){
                         include 'KANBAN1.php';
                    } else if ($_COOKIE["temakaban"]==2){
                         include 'KANBAN2.php';
                    }
                    ?>

                    <div id="DivRodape">
                        <?php include "Rodape.php"; ?>  
                    </div>
                </div>
            </div>
        </div>
    </div>
  <script>
 <?php
 include "./JavaScript/Modal.js";
 ?>
    </script>
</body>
  • 1

    bound ^---^

  • for some reason even I selecting option 2, back to the 1

  • @J.Jones opa, I will test and I warn you

  • edited the question

  • @J.Jones updated the answer, I switched Sessionfor cookie, because the session is destroyed when you close the browser, so it should work better, there was an error in the if too, already fixed.

  • instead of echo should not be include?

  • @J.Jones both inside a include and outside the operation will be the same, the code is just an example of use to explain how it works, you can adapt as you wish.

  • is what gives this error when I put include in place of echo : Warning: include(KANBAN2.php): failed to open stream: No such file or directory in

  • appears on both pages, both on two and on one

  • no need to apologize

  • @J.Jones fixed the code. KANBAN2.php and KANBAN1.php are in the same folder?

  • yes, they’re in the same folder

  • Are you using these includes on other pages? Error Warning: include(KANBAN2.php) continues?

  • 1

    It worked, very obliged

Show 9 more comments

Browser other questions tagged

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