Skip to content
Advertisement

PHP get function is empty for hidden container

I am trying to $_GET a hidden input using PHP.

When I check the html code in Chrome, Safari, etc., I can see the value of the hidden variable but when I try to echo it with PHP it is empty. All of this is inside a modal.

I don’t really understand what I am doing wrong.

I hope some of you can help me.

<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
</form>


<div id="frame" class="modal">

  <div class="modal-content">

    <!-- Body content -->
    <div class="modal-body">

      <p id="content">
      <?php

        // Get information
        $id = $_GET["hiddencontainer"];
        echo $id;
      ?>
      </p>
    </div>

  </div>
</div>

Advertisement

Answer

You need to submit the form to get the value, try this

<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
Click the button to submit the form and you will see the value
<input type="submit" name="Submit form"/>
</form>


<div id="frame" class="modal">

  <div class="modal-content">

    <!-- Body content -->
    <div class="modal-body">

      <p id="content">
      <?php

        // Get information
        $id = $_GET["hiddencontainer"];
        echo $id;
      ?>
      </p>
    </div>

  </div>
</div>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement