I have a problem with the following $_POST
. As you see from the code once the radioButton has value YES and you press submit you are redirected to the page where I put "IdCantiere" = (value random)
and? myInput =
which would be the $_POST
that does not work for me.
The redirect refers to the affidatario.php page in which I make the $_GET
of both variables.
executing a var_dump($_GET)
the only thing that finds is idCantiere. How can I get the value of myInput?
I place my code and some screens
<html>
<body>
<fieldset>
<strong>Vuoi inserire un affidatario?</strong>
<form action="../affidatario.php?idCantiere=<?php echo $idCantiere?>" method="POST" name="prova" onsubmit="return controlla();">
SI<input type="radio" name="scelta" value="si" />
<label name="myLabel" id="myLabel" style="display: none;">Ragione Sociale Affidataria</label><input type="text" id="myInput" style="display: none;"><br>
NO<input type="radio" name="scelta" value="no" /><br />
<button type="submit">INVIA</button>
</form>
</fieldset>
<?php
$myInput=$_POST["myInput"];
?>
<script language="javascript">
function controlla() {
console.log("oie");
x = document.prova;
if (x.scelta.value == "si") {
window.location.href = '../affidatario.php?idCantiere=<?php echo $idCantiere?>?myInput=<?php echo $myInput?>'
return false;
}
if (x.scelta.value == "no") {
alert("Hai risposto no");
window.location.href = '../inserimentoCantiere.php'
return false;
}
}
document.querySelectorAll('input[name="scelta"').forEach(function(a) {
a.addEventListener("change", function() {
let textBox = document.getElementById("myLabel");
if (textBox) textBox.style.display = this.value === "si" ? "block" : "none";
})
});
document.querySelectorAll('input[name="scelta"').forEach(function(a) {
a.addEventListener("change", function() {
let textBox = document.getElementById("myInput");
if (textBox) textBox.style.display = this.value === "si" ? "block" : "none";
})
});
</script>
</body>
</html>
<?php
$idCantiere = $_GET["idCantiere"];
date_default_timezone_set('Europe/Rome');
$date = date('Y-m-d');
chdir("../../../../../Archivio/Cantieri");
opendir(".");
$myInput = $_GET["myInput"];
if(mkdir("../../../../Archivio/Cantieri/".$date."_".$myInput))
{
echo "Cartella account creata con successo! :D";
}
echo "<script type='text/javascript'>alert(myInput);</script>";
var_dump($_GET);
session_start();
if(!isset($_SESSION["username"])){
header('location: ../../../index.php');
}
else
{
?>
