【发布时间】:2018-11-27 14:01:33
【问题描述】:
我对以下$_POST 有疑问。正如您从代码中看到的那样,一旦 radioButton 具有值 YES 并且您按下提交,您将被重定向到我放置 "IdCantiere" = (value random) 的页面并且? myInput = 这将是不适用于我的 $_POST。
重定向指的是 affidatario.php 页面,我在其中创建了两个变量的$_GET。
执行var_dump($_GET) 唯一找到的是idCantiere。如何获取 myInput 的值?
我放置了我的代码和一些屏幕
<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
{
?>
【问题讨论】:
-
我不知道是不是正确答案,但是,如果我没记错的话,$_POST 必须与 'name' 一起使用,而不是与 'id' 一起使用
-
$ MyInput = $ _ POST [ 'myInput "];我觉得是空的 -
不是很清楚..你用post设置了$myinput,但是当你编辑你的输入时$_POST保持为空..所以你必须在你的js文件中检索这个值或者直接从$中检索它_POST 在您的 affidatario.php 文件中
-
Didn't you post something like this already? - 似乎是一种转发形式。
-
是的,但是如果您阅读了问题,您就会明白项目是相同的,而问题是不同的!!! @FunkFortyNiner
标签: javascript php html post get