I find it difficult to solve this problem. I want to use the form input data data from the previous page to show or hide a particular div id.
<form action="http://example.com/example/" method="post">
<input type="hidden" id="example" name="example" value="<?php echo $site; ?>">
<input class="examplesubmit" type="submit" value="Submit">
</form>
page 2
<div id="testing" style="display:none;">
content
</div>
I want the input value or name or id, of the previous page to be used as the basis of div id showing or hidden. if the user hits the submit button, the page automatically displays the content, otherwise the content is not displayed
how should i write it? may use javascript or php code
you would achieve that in a manner like so:
Page 1
<form action="index2.php" method="post">
<input type="hidden" id="example" name="example" value="foo">
<input class="examplesubmit" type="submit" value="Submit">
</form>
Page 2 (index2.php)
<div id="testing"<?php echo ($_POST['example'] == 'foo') ? '' : ' style="display:none;"'; ?>>
konten
</div>
This makes use of the ternary operator which is more or less an inline if/else condition.
So the form on page 1, submits to the form on page 2 (index2.php) in my example and checks that the form field with the name of example has a value set to "foo".