Home > Blockchain >  How to hide a form after being used? PHP
How to hide a form after being used? PHP

Time:07-11

I realize this is quite easy with javascript, however for this problem, please avoid JS. The premise, I am creating a jeopardy board, and I cannot figure out how to hide the question once you've already clicked it from the gameboard. It sounds confusing, but I need the option to disappear once the form has been completed. The following is my code for play.php.

<?PHP session_start();

$category1 = array("x", "x", "x", "x”", "x");
$answer1 = array("x", "x", "x", "x”", "x");

$category2 = array("x", "x", "x", "x”", "x");
$answer2 = array("x", "x", "x", "x”", "x");

$category3 = array("x", "x", "x", "x”", "x");
$answer3 = array("x", "x", "x", "x”", "x");

$category4 = array("x", "x", "x", "x”", "x");
$answer4 = array("x", "x", "x", "x”", "x");
$category5 = array("x", "x", "x", "x”", "x");
$answer5 = array("x", "x", "x", "x”", "x");

$_SESSION["Score"];
  
if (isset($_POST['q1'])){
  $_SESSION["Question"] = $category1[0];
  $_SESSION["Answer"] = $answer1[0];
  $_SESSION["Points"] = 100;
  header("Location: questionPage.php");

just the example of the first few questions. The next code is from play.php as well, running it.

<body>
  <head>
    <link rel="stylesheet" href="play.css" />
  </head>
  <style>

  </style>
  <form method="post">
    <div id="container">
      <table id="board">
        <tr id="categories">
...
        </tr>
      </table>
    </div>
  </form>
</body>

If anyone can help it would be greatly appreciated.

CodePudding user response:

To hide the table, I would recommend using CSS to "hide" your container. For example:

  • Display container:

    <div id="container" style="display:block">
    
  • Hide container:

    <div id="container" style="display:none">
    

You can easily do this with if/else in your "play.php".

CodePudding user response:

In the below code, I am just checking whether the form is submitted or not. If It is submitted $_POST['q1'] will be set and the form will disappear. Try like below,

<?php if(!isset($_POST['q1'])){ ?>
  <form method="post">
    <div id="container">
      <table id="board">
        <tr id="categories">
...
        </tr>
      </table>
    </div>
  </form>
<?php } ?>

But, Once you refresh the page. The form will appear again.

  •  Tags:  
  • php
  • Related