사실 HTML 양식의 입력란을 동적으로 생성하고 있습니다. 내 문제는 양식을 제출할 때 아무것도 내 PHP에 게시되지 않습니다.양식 제출이 jQuery에 의해 동적으로 생성 된 필드를 게시하지 않습니다.
그래서 난 내 PHP에서
echo "<pre>"; print_r($_POST) ; echo "</pre>";
을 사용하고 경우는 하늘의 배열이있다. 실제로 내가 작업하고 있지 않다 때문에
<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 섹션을 무시할 수 있습니다 :
은 여기 내 HTML 형식이다.
('#'+ 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";
>
와이되고 그래서 여기
내가 추가 필드를 작성의 .js 코드입니다. 양식 제출에서 호출되는 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를 변경하면 모든 것이 잘 작동합니다.
POST가 PhpStorm의 통합 서버에서 작동하지 않을 수도 있습니까?
이 해결
문제는 PhpStorm의 통합 서버가 POST 방법 몇 가지 문제를 가지고 있었다. GET으로 모든 것이 잘 작동합니다.
echo "<pre>"; print_r($_POST) ; echo "</pre>";
당신이해야 게시물 배열에 saetze이없는 경우,
그리고 사람이 당신의 입력 유형에게 이름을 부여하는 것을 잊지하지는 출력은 무엇)
입력 이름이 고유해야합니다. 그게 문제입니다. – Jeff
이름 = "maincat"에 대해 이야기하는 것 같습니까? 이론을 테스트하기 위해 그것을 삭제했지만, 여전히 빈 POST 배열이 효과가 없습니다. – webbie
지금 모든 입력에 이름을 부여했지만 아무런 영향이 없습니다. – webbie