其实我为HTML表单动态地生成输入字段。 现在我的问题是提交表单时,什么都不会发布到我的PHP。表单提交不是发布由jQuery动态创建的字段
所以,当我在我的PHP使用
echo "<pre>"; print_r($_POST) ; echo "</pre>";
有一个空数组。
这里是我的html形式:
<form method="POST" action="../php/saveTraining.php" id="trainingForm">
<section id="mainCategory" class="hidden">
<label><input type="checkbox" name="mainCat" id="Krafttraining">Krafttraining</label>
<label><input type="checkbox" name="mainCat" id="Joggen">Joggen</label>
</section>
<section id="categoryKrafttraining" class="hidden">
<label class="subCategory"><input type="checkbox" class="subCategory">Kurzhantel</label>
<label class="subCategory"><input type="checkbox" class="subCategory">Bankdrücken</label>
</section>
<section id="categoryJoggen" class="hidden">
<label><input type="number" name="joggingKm" id="joggingKm">Kilometer</label>
<label><input type="number" name="joggingTime" id="joggingTime">Zeit</label>
</section>
<input type="hidden" id="saveTraining" name="sent" value="save">
</form>
可以忽略第3节,因为其实我不与它合作。
因此,这里的.js文件的代码,我创建的附加字段:
('#'+ category +' :checkbox').off('change').change(function (event) {
console.log("YUP");
sectionID = 'sect'+ $(event.target.parentNode).text();
if (this.checked){
//append input fields
$('#'+category).append('<section id='+sectionID+'><h5>'+$(event.target.parentNode).text()+'</h5><label><input type="number" name="saetze" id="saetze">Sätze</label>' +
'<label><input type="number" name="wiederholungen" id="wiederholungen">Wiederholungen</label></section>');
}else{
console.log("HIER");
//delete not necessary input fields
$('#'+sectionID).remove();
}
});
这里是我的.PHP连接:
<?php
$host= "127.0.0.1";
$user= "censored";
$pw= "censored";
$db= "censored";
$mysqli = new mysqli("localhost", "$db", "$user", "$pw", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") ";
}
echo $mysqli->host_info . "\n";
>
和这里的。从表格调用的PHP提交:
<?php
include ('datenbankConnect.php');
$saetze = $_POST['saetze'];
$wiederholungen = $_POST['wiederholungen'];
echo "werte:";
echo $saetze;
echo "<pre>"; print_r($_POST) ; echo "</pre>";
?>
所以在提交表单的时候我也从我的PHP收到以下消息:
注意:未定义指数:
注意:未定义指数:
也许你能帮助我。这会很棒!
所以method="post"
有问题。当我使用method="get"
,并相应地更改PHP的GET一切工作正常。
所以POST可能不适用于PhpStorm的集成服务器吗?
解决
的问题是,PhpStorm的集成服务器与POST方法的一些问题。随着GET一切正常。
和球员,不要忘了给你的输入类型的名称;)
输入的名称必须是唯一的,我想这就是问题所在。 – Jeff
我想你说的是名字=“maincat”? 我删除它来测试你的理论,但它没有效果,仍然有一个空的POST数组。 – webbie
现在我给所有的输入一个名字,但它没有效果 – webbie