Garder la visibilité après un submit
Posté : 04 oct. 2014, 11:17
Bonjour, je débute et dans ce programme épuré je souhaite garder la visibilité de "hiddenform1" ou "hiddenform2" après avoir appuyé sur submit.
Je n'ai pas trouvé de solutions. Des idées pour éviter qu'ils redeviennent invisible après un submit? Merci pour votre aide.
Guy
debugform.php:
Je n'ai pas trouvé de solutions. Des idées pour éviter qu'ils redeviennent invisible après un submit? Merci pour votre aide.
Guy
debugform.php:
<html>
<head>
<title>Hide Form</title>
<script type="text/javascript">
function showForm(flag) {
document.getElementById('hiddenform1').style.visibility = flag >= 1 ? 'visible' : 'hidden';
document.getElementById('hiddenform2').style.visibility = flag >= 2 ? 'visible' : 'hidden';
}
</script>
<style type="text/css">
#hiddenform1 {visibility: hidden}
#hiddenform2 {visibility: hidden}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$nb = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["nb"])) {
$nb ="";
} else {
$nb = test_input($_POST["nb"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
Enter a number
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
1:<input type="radio" name="nb" value="1" onclick="showForm(1);" <?php if (isset($nb) && $nb=="1") echo "checked"; ?>>  
2:<input type="radio" name="nb" value="2" onclick="showForm(2);" <?php if (isset($nb) && $nb=="2") echo "checked"; ?>>  
<br><br>
<div id="hiddenform1">
<?php include("fa1.php"); ?>
</div>
<div id="hiddenform2">
<?php include("fa2.php"); ?>
</div>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Your Input:</h2>";
echo $nb;
echo "<br>";
?>
</body>
</html>
fa1.php:
Quantity 1:<input type="number" name="quantity1" value ="100" readonly>
fa2.php:
Quantity 2:<input type="number" name="quantity2" value ="100" readonly>