jquery-양식 제출시 일부 입력 게시물 데이터 만 전달하는 동적으로 생성 된 양식 (양식이 조기에 닫힘)

Khaverim

jQuery를 통해 동적으로 생성되는 전체 양식이 있습니다. 양식의 끝에 있는 onclick이벤트 와 함께 잘 제출 <input type="button">됩니다 ( 참고 : 양식 <input type="submit"> . 함께 제출 되지 않습니다 . 이유는 모르겠지만 관련성이있을 수 있습니다. ). 내 문제는 어떤 이유로 print_r($_POST);제출 후 두 개의 $_POST데이터, 즉 name = selectedID 및 name = CustomID전달 된다는 것 입니다. 나머지는 <input>데이터를 전달하지 않습니다.

양식이 생성되는 방법은 다음과 같습니다.

var sid = servHTMLid.replace("serviceSel", "");

var cidText = $("#" + servHTMLid + " td:nth-child(2)").html();
$("#" + servHTMLid + " td:nth-child(2)").html("<form name='serviceForm' id='serviceForm' method='POST' action='services.php?save'><input type='hidden' name='selectedID' id='selectedID' value='" + sid + "' /><input type='text' name='CustomID' id='CustomID' value='" + cidText + "' />");

// seems like from here out, these inputs don't POST
var catText = $("#" + servHTMLid + " td:nth-child(3)").html();
$("#" + servHTMLid + " td:nth-child(3)").html("<input type='text' name='Category' id='Category' value='" + catText + "' />");

var nameText = $("#" + servHTMLid + " td:nth-child(4)").html();
$("#" + servHTMLid + " td:nth-child(4)").html("<input type='text' name='Name' id='Name' value='" + nameText + "' />");

var durationText = $("#" + servHTMLid + " td:nth-child(5)").html();
$("#" + servHTMLid + " td:nth-child(5)").html("<input type='text' name='Duration' id='Duration' value='" + durationText + "' />");

var priceText = parseFloat($("#" + servHTMLid + " td:nth-child(6)").html()).toFixed(2);
$("#" + servHTMLid + " td:nth-child(6)").html("<input type='text' name='Price' id='Price' value='" + priceText + "' />");

var taxText = $("#" + servHTMLid + " td:nth-child(7)").html();
if (taxText == "yes") {
  $("#" + servHTMLid + " td:nth-child(7)").html("<input type='checkbox' name='Tax' id='Tax' checked />");
} else {
  $("#" + servHTMLid + " td:nth-child(7)").html("<input type='checkbox' name='Tax' id='Tax' />");
}

var InactiveText = $("#" + servHTMLid + " td:nth-child(8)").html();
if (InactiveText == "yes") {
  $("#" + servHTMLid + " td:nth-child(8)").html("<input type='checkbox' name='Inactive' id='Inactive' checked />");
} else {
  $("#" + servHTMLid + " td:nth-child(8)").html("<input type='checkbox' name='Inactive' id='Inactive' />");
}

$("#" + servHTMLid + " td:nth-child(9)").html('<input type="button" value="save" name="serviceFormSubmit" id="serviceFormSubmit" onclick="submitForm();" /></form>');

다음은 동적으로 생성 된 후 양식 ( '저장'버튼 사용)을 제출하려는 스크린 샷입니다. 여기에 이미지 설명 입력

print_r($_POST);제출 후 출력 은 다음과 같습니다 .여기에 이미지 설명 입력

$ _POST [ 'Category'] 또는 $ _POST [ 'Name'] 등이 없습니다.

좋은 측정을 위해 이것은 버튼의 onclick 이벤트에 의해 호출되는 제출 함수입니다.

function submitForm()
{
 $("#serviceForm").submit();
}

편집 : 방금 생성 된 HTML이 양식을 너무 일찍 닫는다는 것을 알았습니다 .. ??

   <table class="services" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr id="serviceSel6" onclick="openEdits(this.id);">
<td>6</td>
<td>
<form id="serviceForm" action="services.php?save" method="POST" name="serviceForm">
<input id="selectedID" type="hidden" value="6" name="selectedID">
<input id="CustomID" type="text" value="Massage 09" name="CustomID">
</form> // <----- THIS... why?
</td>
<td>
<input id="Category" type="text" value="" name="Category">
</td>
<td>
<input id="Name" type="text" value="Mass Reflexology" name="Name"> // .....etc.
PeterKA

같은 동적 HTML을 생성하는 jQuery를 방법을 사용에 대한주의 html(), append()등이있다.

닫는 태그가없는 여는 태그에는 해당하는 닫는 태그가 제공됩니다. 그것이 </form>당신이 그것을 보는 곳에 나타나는 이유 입니다.

.html("<form name='serviceForm' id='serviceForm' method='POST' action='services.php?save'><input type='hidden' name='selectedID' id='selectedID' value='" + sid + "' /><input type='text' name='CustomID' id='CustomID' value='" + cidText + "' />");

html()</form>문자열 끝에가 표시되지 않았으므로 하나를 추가했습니다. 일반적으로 전체 양식 문자열 을 구성하는 데 시간이 걸리고 적절한 메서드를 호출합니다.

.html( 'Well-formed HTML String' )

JS FIDDLE <---- 콘솔 출력을 확인합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관